From 9229cdae8a70f6c20cc8dc5e0077471fd7568aa5 Mon Sep 17 00:00:00 2001 From: kookiekenobi Date: Sun, 2 Feb 2025 01:44:59 +0800 Subject: [PATCH] game: paper interaction pt4 debugs for paper in socket --- SSLR/Assets/Scenes/LiviPlayground.unity | 32 +++++++++++++- SSLR/Assets/Scripts/NPCBehaviour.cs | 6 +++ SSLR/Assets/Scripts/PaperSocket.cs | 59 +++++++++++++++++++++++++ SSLR/Assets/Scripts/PaperSocket.cs.meta | 11 +++++ SSLR/Assets/Scripts/Player.cs | 2 +- 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 SSLR/Assets/Scripts/PaperSocket.cs create mode 100644 SSLR/Assets/Scripts/PaperSocket.cs.meta diff --git a/SSLR/Assets/Scenes/LiviPlayground.unity b/SSLR/Assets/Scenes/LiviPlayground.unity index eecc8c8..fcb5ab6 100644 --- a/SSLR/Assets/Scenes/LiviPlayground.unity +++ b/SSLR/Assets/Scenes/LiviPlayground.unity @@ -474,6 +474,7 @@ GameObject: - component: {fileID: 370788366} - component: {fileID: 370788365} - component: {fileID: 370788364} + - component: {fileID: 370788367} m_Layer: 0 m_Name: Paper Socket_NPC m_TagString: Untagged @@ -590,6 +591,19 @@ BoxCollider: serializedVersion: 3 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} +--- !u!114 &370788367 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 370788362} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 120dec3a4fef31d4c8b88a1e19de3d80, type: 3} + m_Name: + m_EditorClassIdentifier: + socketName: Paper Socket_NPC --- !u!1 &397894337 GameObject: m_ObjectHideFlags: 0 @@ -2688,6 +2702,7 @@ GameObject: - component: {fileID: 1938714096} - component: {fileID: 1938714095} - component: {fileID: 1938714098} + - component: {fileID: 1938714099} m_Layer: 0 m_Name: Paper Socket m_TagString: Untagged @@ -2751,8 +2766,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1938714094} serializedVersion: 2 - m_LocalRotation: {x: -0, y: 0.9904229, z: -0, w: 0.13806713} - m_LocalPosition: {x: -0.072, y: 0.893, z: 1.389} + m_LocalRotation: {x: 0, y: 0.9904229, z: 0, w: 0.13806683} + m_LocalPosition: {x: -0.645, y: 0.893, z: 1.389} m_LocalScale: {x: 0.45395544, y: 0.014691553, z: 0.57689166} m_ConstrainProportionsScale: 0 m_Children: [] @@ -2804,6 +2819,19 @@ MonoBehaviour: m_SocketScaleMode: 0 m_FixedScale: {x: 1, y: 1, z: 1} m_TargetBoundsSize: {x: 1, y: 1, z: 1} +--- !u!114 &1938714099 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1938714094} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 120dec3a4fef31d4c8b88a1e19de3d80, type: 3} + m_Name: + m_EditorClassIdentifier: + socketName: Paper Socket --- !u!1 &2027209538 GameObject: m_ObjectHideFlags: 0 diff --git a/SSLR/Assets/Scripts/NPCBehaviour.cs b/SSLR/Assets/Scripts/NPCBehaviour.cs index 489b2f9..81eb091 100644 --- a/SSLR/Assets/Scripts/NPCBehaviour.cs +++ b/SSLR/Assets/Scripts/NPCBehaviour.cs @@ -18,6 +18,8 @@ public class NPCBehaviour : MonoBehaviour [SerializeField] private GameObject navigationTxtBubble; [SerializeField] public TextMeshProUGUI navigationTxt; + public static bool paperProduced; + private string[] possibleSentences = { "I want to go left!", @@ -31,6 +33,8 @@ public class NPCBehaviour : MonoBehaviour paperObject.SetActive(false); navigationTxtBubble.SetActive(false); + paperProduced = false; + if (navigationTxt != null) { navigationTxt.text = GetRandomSentence(); @@ -43,6 +47,8 @@ public class NPCBehaviour : MonoBehaviour { paperObject.SetActive(true); navigationTxtBubble.SetActive(true); + + paperProduced = true; } } diff --git a/SSLR/Assets/Scripts/PaperSocket.cs b/SSLR/Assets/Scripts/PaperSocket.cs new file mode 100644 index 0000000..4e7e4e3 --- /dev/null +++ b/SSLR/Assets/Scripts/PaperSocket.cs @@ -0,0 +1,59 @@ +/* + * Author: Livinia Poo + * Date: 1/2/25 + * Description: + * Paper Handling + Interaction*/ + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.XR.Interaction.Toolkit; +using UnityEngine.XR.Interaction.Toolkit.Interactors; + +public class PaperSocket : MonoBehaviour +{ + [SerializeField] private string socketName; + XRSocketInteractor interactor; + + void Awake() + { + interactor = GetComponent(); + } + + void OnEnable() + { + interactor.selectEntered.AddListener(OnPaperAttached); + interactor.selectExited.AddListener(OnPaperDetached); + } + + void OnDisable() + { + interactor.selectEntered.RemoveListener(OnPaperAttached); + interactor.selectExited.RemoveListener(OnPaperDetached); + } + + private void OnPaperAttached(SelectEnterEventArgs args) + { + if (socketName == "Paper Socket_NPC") + { + Debug.Log("Paper returned to NPC"); + } + else if (socketName == "Paper Socket") + { + Debug.Log("Paper placed on table"); + } + } + + private void OnPaperDetached(SelectExitEventArgs args) + { + if (socketName == "Paper Socket_NPC") + { + Debug.Log("Paper taken from NPC"); + } + else if (socketName == "Paper Socket") + { + Debug.Log("Paper removed from table"); + } + } +} diff --git a/SSLR/Assets/Scripts/PaperSocket.cs.meta b/SSLR/Assets/Scripts/PaperSocket.cs.meta new file mode 100644 index 0000000..14f35fc --- /dev/null +++ b/SSLR/Assets/Scripts/PaperSocket.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 120dec3a4fef31d4c8b88a1e19de3d80 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SSLR/Assets/Scripts/Player.cs b/SSLR/Assets/Scripts/Player.cs index 9a8e82d..1cd8e42 100644 --- a/SSLR/Assets/Scripts/Player.cs +++ b/SSLR/Assets/Scripts/Player.cs @@ -27,7 +27,7 @@ public class Player : MonoBehaviour void CheckDayEnd() { - if (score <= 0) + if (score < 0) { Debug.Log("Game Over, Day has ended"); gm.dayEnded = true;