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

@ -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<NavMeshAgent>();
animator = gameObject.GetComponent<Animator>();
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);
}

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()