diff --git a/SSLR/Assets/Scenes/LiviPlayground.unity b/SSLR/Assets/Scenes/LiviPlayground.unity index d3d663f..8dd3972 100644 --- a/SSLR/Assets/Scenes/LiviPlayground.unity +++ b/SSLR/Assets/Scenes/LiviPlayground.unity @@ -2031,6 +2031,7 @@ GameObject: - component: {fileID: 272065566} - component: {fileID: 272065565} - component: {fileID: 272065564} + - component: {fileID: 272065568} m_Layer: 5 m_Name: PlayerDialogue m_TagString: Untagged @@ -2124,6 +2125,25 @@ RectTransform: m_AnchoredPosition: {x: 1.184, y: 1.477} m_SizeDelta: {x: 659.8499, y: 515.963} m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &272065568 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 272065563} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7951c64acb0fa62458bf30a60089fe2d, type: 3} + m_Name: + m_EditorClassIdentifier: + m_IgnoreReversedGraphics: 0 + m_CheckFor2DOcclusion: 0 + m_CheckFor3DOcclusion: 0 + m_BlockingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RaycastTriggerInteraction: 1 --- !u!1 &278641001 GameObject: m_ObjectHideFlags: 0 diff --git a/SSLR/Assets/Scripts/Backend.cs b/SSLR/Assets/Scripts/Backend.cs index 8f6c3e9..eda1b19 100644 --- a/SSLR/Assets/Scripts/Backend.cs +++ b/SSLR/Assets/Scripts/Backend.cs @@ -119,8 +119,21 @@ public class Backend : MonoBehaviour { DataSnapshot snapshot = task.Result; string json = snapshot.GetRawJsonValue(); - data = JsonUtility.FromJson(json); - target.npcData = data; + + if (!string.IsNullOrEmpty(json)) + { + target.npcData = JsonUtility.FromJson(json); + Debug.Log($"NPC Loaded: {target.npcData.initialStatement}"); + + if (GameManager.instance.currentNPC == target.gameObject) + { + target.LoadNPCDialogue(); + } + } + else + { + Debug.LogError("Firebase returned empty"); + } } ; diff --git a/SSLR/Assets/Scripts/GameManager.cs b/SSLR/Assets/Scripts/GameManager.cs index f3e33c9..503cbec 100644 --- a/SSLR/Assets/Scripts/GameManager.cs +++ b/SSLR/Assets/Scripts/GameManager.cs @@ -23,16 +23,14 @@ public class GameManager : MonoBehaviour public bool dayEnded = false; public bool shiftStarted; + /// + /// NPC in front of desk + /// public GameObject currentNPC; - - /*[Header("Walk Points (FOR DEBUGGING")] - public Transform[] frontWalkPoints; - public Transform[] leftWalkPoints; - public Transform[] rightWalkPoints; - - public GameObject leftWalkPointSet; - public GameObject rightWalkPointSet;*/ - + + /// + /// References for player-npc dialogue + /// [Header("NPC Dialogue")] public TextMeshProUGUI playerQuestionOneText; public TextMeshProUGUI playerQuestionTwoText; @@ -58,5 +56,14 @@ public class GameManager : MonoBehaviour } playerDialogue.SetActive(false); - } + } + + /// + /// Setting NPC in front of desk as current + /// + /// + public void SetCurrentNPC(GameObject npc) + { + currentNPC = npc; + } } diff --git a/SSLR/Assets/Scripts/NPCMovementRework.cs b/SSLR/Assets/Scripts/NPCMovementRework.cs index 5feed5b..f382256 100644 --- a/SSLR/Assets/Scripts/NPCMovementRework.cs +++ b/SSLR/Assets/Scripts/NPCMovementRework.cs @@ -51,9 +51,7 @@ public class NpcMovementRework : MonoBehaviour Backend.instance.FirebaseGet(this); npcSpeechBubble.SetActive(false); - StartCoroutine(SitDown()); - LoadNPCDialogue(); } public void Called() @@ -65,18 +63,26 @@ public class NpcMovementRework : MonoBehaviour { var pos = NpcManager.instance.desk; agent.SetDestination(pos.position); + while (true) { var npcpos = gameObject.transform.position; npcpos.y = 0; var dist= Vector3.Distance(pos.position,npcpos); + if (dist<0.5f) { agent.SetDestination(gameObject.transform.position); gameObject.transform.rotation = pos.transform.rotation; + GameManager.instance.SetCurrentNPC(this.gameObject); + npcSpeechBubble.SetActive(true); GameManager.instance.playerDialogue.SetActive(true); + Debug.Log($"{gameObject.name} reached desk"); + + yield return new WaitUntil(() => npcData != null); + LoadNPCDialogue(); break; } @@ -125,8 +131,17 @@ public class NpcMovementRework : MonoBehaviour public void LoadNPCDialogue() { - Debug.Log("Loading NPC Dialogue"); - Debug.Log(npcData.initialStatement); + if (GameManager.instance.currentNPC != this.gameObject) + { + return; + } + + if (npcData == null) + { + Debug.LogError($"NPC Data is null for {gameObject.name}"); + return; + } + initialStatementText.text = npcData.initialStatement; GameManager.instance.playerQuestionOneText.text = npcData.question1; diff --git a/SSLR/Assets/Scripts/NextButton.cs b/SSLR/Assets/Scripts/NextButton.cs index 51585b4..e569c3d 100644 --- a/SSLR/Assets/Scripts/NextButton.cs +++ b/SSLR/Assets/Scripts/NextButton.cs @@ -2,10 +2,15 @@ using UnityEngine; public class NextButton : MonoBehaviour { + /// + /// Next NPC to desk based on scene list + /// public void CallNext() { var npcs = NpcManager.instance.currentNpcs; var randomnpc = npcs[Random.Range(0, npcs.Count)]; + + GameManager.instance.SetCurrentNPC(randomnpc); randomnpc.GetComponent().Called(); } }