From 5953046a78760b16982ad47ef57a5f04acef6c0a Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 17 Feb 2025 02:05:31 +0800 Subject: [PATCH] game: die my workl has ended --- SSLR/Assets/Scenes/LiviPlayground.unity | 15 +---- SSLR/Assets/Scripts/GameManager.cs | 2 +- SSLR/Assets/Scripts/NPCMovementRework.cs | 80 ++++++++++++++++-------- SSLR/Assets/Scripts/NpcManager.cs | 8 +++ SSLR/Assets/Scripts/ShiftManager.cs | 1 + 5 files changed, 65 insertions(+), 41 deletions(-) diff --git a/SSLR/Assets/Scenes/LiviPlayground.unity b/SSLR/Assets/Scenes/LiviPlayground.unity index 35c5374..c26a8ba 100644 --- a/SSLR/Assets/Scenes/LiviPlayground.unity +++ b/SSLR/Assets/Scenes/LiviPlayground.unity @@ -5535,7 +5535,6 @@ GameObject: - component: {fileID: 520849220} - component: {fileID: 520849219} - component: {fileID: 520849216} - - component: {fileID: 520849217} - component: {fileID: 520849218} m_Layer: 0 m_Name: Game Manager @@ -5575,18 +5574,6 @@ MonoBehaviour: shiftStarted: 0 currentNPC: {fileID: 0} currentNPCCorrectDepartment: ---- !u!114 &520849217 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 520849214} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 8c6fa011a2b389049b558ccdf6b38c38, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!114 &520849218 MonoBehaviour: m_ObjectHideFlags: 0 @@ -6764,7 +6751,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0bab791ccf13189449b82b8f0b70b269, type: 3} m_Name: m_EditorClassIdentifier: - shiftDuration: 60 + shiftDuration: 20 npcSpawnArea: {fileID: 1126609776} --- !u!1 &741702766 GameObject: diff --git a/SSLR/Assets/Scripts/GameManager.cs b/SSLR/Assets/Scripts/GameManager.cs index 400629f..dc4fc31 100644 --- a/SSLR/Assets/Scripts/GameManager.cs +++ b/SSLR/Assets/Scripts/GameManager.cs @@ -52,7 +52,7 @@ public class GameManager : MonoBehaviour public void SetCurrentNPC(GameObject npc) { currentNPC = npc; - + NpcManager.instance.currentNpcs.Remove(npc); NpcMovementRework npcScript = npc.GetComponent(); if (npcScript != null) { diff --git a/SSLR/Assets/Scripts/NPCMovementRework.cs b/SSLR/Assets/Scripts/NPCMovementRework.cs index 63ae87d..465a214 100644 --- a/SSLR/Assets/Scripts/NPCMovementRework.cs +++ b/SSLR/Assets/Scripts/NPCMovementRework.cs @@ -31,10 +31,10 @@ public class NpcMovementRework : MonoBehaviour [SerializeField] private GameObject npcSpeechBubble; [SerializeField] private GameObject npcAnswerPanel; - + public NpcData npcData; public string correctService; - + public void Update() { if (agent.velocity.magnitude > 0.1) @@ -53,7 +53,7 @@ public class NpcMovementRework : MonoBehaviour agent = gameObject.GetComponent(); animator = gameObject.GetComponent(); Backend.instance.FirebaseGet(this); - + npcSpeechBubble.SetActive(false); npcAnswerPanel.SetActive(false); StartCoroutine(SitDown()); @@ -63,33 +63,33 @@ public class NpcMovementRework : MonoBehaviour { StartCoroutine(CustomerCalled()); } - + public IEnumerator CustomerCalled() { 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) + 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); npcAnswerPanel.SetActive(true); PlayerDialogueInteraction.instance.playerDialogue.SetActive(true); - + yield return new WaitUntil(() => npcData != null); correctService = npcData.correctDepartment; - + LoadNPCDialogue(); break; } @@ -105,36 +105,64 @@ public class NpcMovementRework : MonoBehaviour var seat = NpcManager.instance.Seats[i]; while (!seat.Available) { - i = Random.Range(0, NpcManager.instance.Seats.Length); - seat = NpcManager.instance.Seats[i]; - yield return new WaitForSeconds(2f); + i = Random.Range(0, NpcManager.instance.Seats.Length); + seat = NpcManager.instance.Seats[i]; + yield return new WaitForSeconds(2f); } - + seat.Available = false; var sittingPosition = seat.SeatObject.transform.position; sittingPosition.y = 0; agent.SetDestination(sittingPosition); - + while (true) { - var dist= Vector3.Distance(sittingPosition,gameObject.transform.position); + var dist = Vector3.Distance(sittingPosition, gameObject.transform.position); if (dist < 0.05f) { agent.SetDestination(gameObject.transform.position); animator.SetBool(IsSitting, true); gameObject.transform.rotation = seat.SeatObject.transform.rotation; - + break; } + + yield return 0; + } + } + + + public void Despawn(bool endDay = false) + { + if (endDay) + { + var random = Random.Range(0, NpcManager.instance.spawnPoints.Length); + StartCoroutine(DespawnWhenReached(NpcManager.instance.spawnPoints[random])); + } + else + { + var random = Random.Range(0, NpcManager.instance.despawnPoints.Length); + StartCoroutine(DespawnWhenReached(NpcManager.instance.despawnPoints[random])); + } + } + + private IEnumerator DespawnWhenReached(Transform destination) + { + agent.SetDestination(destination.position); + while (true) + { + var dist = Vector3.Distance(destination.position, gameObject.transform.position); + if (dist < 1) + { + agent.SetDestination(gameObject.transform.position); + Destroy(gameObject); + break; + } + yield return 0; } } - public void Despawn() - { - var random = Random.Range(0, NpcManager.instance.despawnPoints.Length); - agent.SetDestination(NpcManager.instance.despawnPoints[random].position); - } public void LoadNPCDialogue() { @@ -151,13 +179,13 @@ public class NpcMovementRework : MonoBehaviour npcWelcomeText.text = "Hello"; initialStatementText.text = npcData.initialStatement; - + npcAnswerOneText.text = npcData.answer1; npcAnswerTwoText.text = npcData.answer2; npcAnswerThreeText.text = npcData.answer3; npcClarifiedResponse.text = "I see..."; - + PlayerDialogueInteraction.instance.SetPlayerQuestions(npcData.question1, npcData.question2, npcData.question3); PlayerDialogueInteraction.instance.SetPlayerResposne(npcData.response3); } diff --git a/SSLR/Assets/Scripts/NpcManager.cs b/SSLR/Assets/Scripts/NpcManager.cs index 50837c9..ec5d3f8 100644 --- a/SSLR/Assets/Scripts/NpcManager.cs +++ b/SSLR/Assets/Scripts/NpcManager.cs @@ -136,6 +136,14 @@ public class NpcManager : MonoBehaviour isSpawning = false; } + public void EndDay() + { + foreach (var npc in currentNpcs) + { + npc.GetComponent().Despawn(true); + } + } + [Serializable] public struct Seat { diff --git a/SSLR/Assets/Scripts/ShiftManager.cs b/SSLR/Assets/Scripts/ShiftManager.cs index 7c4acb2..b9afc5d 100644 --- a/SSLR/Assets/Scripts/ShiftManager.cs +++ b/SSLR/Assets/Scripts/ShiftManager.cs @@ -70,6 +70,7 @@ public class ShiftManager : MonoBehaviour remainingTime = shiftDuration; gm.shiftStarted = false; dayManager.doneAShift = true; + NpcManager.instance.EndDay(); } public void AllowShiftStart()