From 63e88c3a272ca380d7797fabd3e5836b1ce7a1c6 Mon Sep 17 00:00:00 2001 From: Antoine H Date: Sun, 17 Jan 2021 13:39:56 +0100 Subject: [PATCH] Change client spawn logic (coroutine) --- Assets/Scenes/Tests/SampleScene.unity | 5 ++ Assets/Scripts/Client_controller.cs | 4 +- Assets/Scripts/GameSystems/ClientManager.cs | 54 ++++++++++++++------- Assets/Scripts/GameSystems/GameSystem.cs | 8 ++- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/Assets/Scenes/Tests/SampleScene.unity b/Assets/Scenes/Tests/SampleScene.unity index 097bf25..b53e284 100644 --- a/Assets/Scenes/Tests/SampleScene.unity +++ b/Assets/Scenes/Tests/SampleScene.unity @@ -32568,6 +32568,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 2157073179154264261, guid: dfb09d229e85c1446bee2e4f9357610e, + type: 3} + propertyPath: nbMaxClients + value: 3 + objectReference: {fileID: 0} - target: {fileID: 2157073180203202245, guid: dfb09d229e85c1446bee2e4f9357610e, type: 3} propertyPath: m_Name diff --git a/Assets/Scripts/Client_controller.cs b/Assets/Scripts/Client_controller.cs index 3880613..ab24930 100644 --- a/Assets/Scripts/Client_controller.cs +++ b/Assets/Scripts/Client_controller.cs @@ -136,8 +136,6 @@ public class Client_controller : MonoBehaviour, IUsable if(status=="entering" && !agent.pathPending && agent.remainingDistance==0) //Reached seat ? { - EventManager.Instance.spawnEvent(transform.position); - status="waiting"; waitTimer=waitingTime; order = ClientManager.Instance.assignOrder(); @@ -162,7 +160,7 @@ public class Client_controller : MonoBehaviour, IUsable if(status=="consuming") //Consuming mug if there's one and reached destination { consumeTimer -= Time.deltaTime; - if (consumeTimer < 0) //Finished consuming mug ? + if(consumeTimer < 0) //Finished consuming mug ? { Mug obj = currentMug.GetComponent(); if(obj !=null) diff --git a/Assets/Scripts/GameSystems/ClientManager.cs b/Assets/Scripts/GameSystems/ClientManager.cs index 521627a..05262b6 100644 --- a/Assets/Scripts/GameSystems/ClientManager.cs +++ b/Assets/Scripts/GameSystems/ClientManager.cs @@ -22,10 +22,14 @@ public sealed class ClientManager : MonoBehaviour [SerializeField] int nbMaxClients = 1; //Maximum active clients [SerializeField] - float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that) + float clientSpawnChance = 100.0f; //Chance of new client every request [SerializeField] - float maxTimeNewClients = 2.0f; //Longest waiting time for new clients - bool clientSpawnReady = false; + float clientFrequency = 1.0f; //Time (s) between clientRequest + // [SerializeField] + // float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that) + // [SerializeField] + // float maxTimeNewClients = 2.0f; //Longest waiting time for new clients + // bool clientSpawnReady = false; [SerializeField] string ClientRessourceFolder = "Clients"; @@ -38,9 +42,9 @@ public sealed class ClientManager : MonoBehaviour //Request new client //Return wether a new client was created - public bool clientRequest() + public bool clientRequest(float SpawnChance=100.0f) { - if(clientSpawnReady && clientIDs.Count