game: die my workl has ended

This commit is contained in:
ryan 2025-02-17 02:05:31 +08:00
parent 743dc76913
commit 5953046a78
5 changed files with 65 additions and 41 deletions

View file

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

View file

@ -52,7 +52,7 @@ public class GameManager : MonoBehaviour
public void SetCurrentNPC(GameObject npc)
{
currentNPC = npc;
NpcManager.instance.currentNpcs.Remove(npc);
NpcMovementRework npcScript = npc.GetComponent<NpcMovementRework>();
if (npcScript != null)
{

View file

@ -126,15 +126,43 @@ public class NpcMovementRework : MonoBehaviour
break;
}
yield return 0;
}
}
public void Despawn()
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);
agent.SetDestination(NpcManager.instance.despawnPoints[random].position);
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 LoadNPCDialogue()
{

View file

@ -136,6 +136,14 @@ public class NpcManager : MonoBehaviour
isSpawning = false;
}
public void EndDay()
{
foreach (var npc in currentNpcs)
{
npc.GetComponent<NpcMovementRework>().Despawn(true);
}
}
[Serializable]
public struct Seat
{

View file

@ -70,6 +70,7 @@ public class ShiftManager : MonoBehaviour
remainingTime = shiftDuration;
gm.shiftStarted = false;
dayManager.doneAShift = true;
NpcManager.instance.EndDay();
}
public void AllowShiftStart()