game: npc scenarios + player dialogue ui

This commit is contained in:
kookiekenobi 2025-02-16 04:47:32 +08:00
parent 58eaaebfe7
commit cf8bad3908
5 changed files with 76 additions and 16 deletions

View file

@ -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

View file

@ -119,8 +119,21 @@ public class Backend : MonoBehaviour
{
DataSnapshot snapshot = task.Result;
string json = snapshot.GetRawJsonValue();
data = JsonUtility.FromJson<NpcData>(json);
target.npcData = data;
if (!string.IsNullOrEmpty(json))
{
target.npcData = JsonUtility.FromJson<NpcData>(json);
Debug.Log($"NPC Loaded: {target.npcData.initialStatement}");
if (GameManager.instance.currentNPC == target.gameObject)
{
target.LoadNPCDialogue();
}
}
else
{
Debug.LogError("Firebase returned empty");
}
}
;

View file

@ -23,16 +23,14 @@ public class GameManager : MonoBehaviour
public bool dayEnded = false;
public bool shiftStarted;
/// <summary>
/// NPC in front of desk
/// </summary>
public GameObject currentNPC;
/*[Header("Walk Points (FOR DEBUGGING")]
public Transform[] frontWalkPoints;
public Transform[] leftWalkPoints;
public Transform[] rightWalkPoints;
public GameObject leftWalkPointSet;
public GameObject rightWalkPointSet;*/
///<summary>
/// References for player-npc dialogue
/// </summary>
[Header("NPC Dialogue")]
public TextMeshProUGUI playerQuestionOneText;
public TextMeshProUGUI playerQuestionTwoText;
@ -58,5 +56,14 @@ public class GameManager : MonoBehaviour
}
playerDialogue.SetActive(false);
}
}
/// <summary>
/// Setting NPC in front of desk as current
/// </summary>
/// <param name="npc"></param>
public void SetCurrentNPC(GameObject npc)
{
currentNPC = npc;
}
}

View file

@ -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;

View file

@ -2,10 +2,15 @@ using UnityEngine;
public class NextButton : MonoBehaviour
{
/// <summary>
/// Next NPC to desk based on scene list
/// </summary>
public void CallNext()
{
var npcs = NpcManager.instance.currentNpcs;
var randomnpc = npcs[Random.Range(0, npcs.Count)];
GameManager.instance.SetCurrentNPC(randomnpc);
randomnpc.GetComponent<NpcMovementRework>().Called();
}
}