Add more interface w/ Unity Inspector and Managers
This commit is contained in:
parent
4f99687ae2
commit
901a2b6c10
4 changed files with 168 additions and 69 deletions
|
@ -6,10 +6,13 @@ using UnityEditor;
|
|||
//Define the system managing the clients. (Singleton)
|
||||
public sealed class ClientManager : MonoBehaviour
|
||||
{
|
||||
int nbMaxClients = 3;
|
||||
[HideInInspector]
|
||||
public bool ready = false; //Wether the ClientManager is initialized
|
||||
|
||||
public int nbMaxClients = 3;
|
||||
bool clientSpawnReady = false;
|
||||
float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that)
|
||||
float maxTimeNewClients = 2.0f;
|
||||
public float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that)
|
||||
public float maxTimeNewClients = 2.0f; //Longest waiting time for new clients
|
||||
|
||||
string ClientRessourceFolder = "Clients";
|
||||
private Object[] clients;
|
||||
|
@ -53,6 +56,12 @@ public sealed class ClientManager : MonoBehaviour
|
|||
Destroy(client);
|
||||
// Debug.Log(client.name+" destroyed"+clientIDs.Count);
|
||||
|
||||
//Prevent immediate spawn of a new client after one leaving
|
||||
if(clientSpawnReady)
|
||||
{
|
||||
clientSpawnReady=false;
|
||||
clientSpawnTimer+=0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
//Return a random available target. Or the Exit if Exit=True.
|
||||
|
@ -91,59 +100,64 @@ public sealed class ClientManager : MonoBehaviour
|
|||
//Awake is called when the script instance is being loaded.
|
||||
void Awake()
|
||||
{
|
||||
ClientContainer = GameObject.Find("/GameSystem/ClientManager");
|
||||
if (ClientContainer is null)
|
||||
throw new System.Exception("No ClientManager found under GameSystem");
|
||||
|
||||
// Load clients prefabs //
|
||||
|
||||
// Find all assets labelled with 'usable' :
|
||||
// string[] guids = AssetDatabase.FindAssets("", new string[] {"Assets/Prefabs/Characters/Clients"});
|
||||
|
||||
// foreach (string guid in guids)
|
||||
// {
|
||||
// Debug.Log(AssetDatabase.GUIDToAssetPath(guid));
|
||||
// Instantiate(guid, spawnPosition, Quaternion.identity);
|
||||
// }
|
||||
|
||||
clients = Resources.LoadAll(ClientRessourceFolder);
|
||||
|
||||
// foreach (var c in clients)
|
||||
// {
|
||||
// Debug.Log(gameObject.name+" : "+c.name + " loaded");
|
||||
// }
|
||||
if (clients.Length<nbMaxClients)
|
||||
if(!ready)
|
||||
{
|
||||
Debug.LogWarning("ClientManager doesn't have enough client prefab to manage unique MaxClients : "+clients.Length+"/"+nbMaxClients);
|
||||
}
|
||||
ClientContainer = GameObject.Find("/GameSystem/ClientManager");
|
||||
if (ClientContainer is null)
|
||||
throw new System.Exception("No ClientManager found under GameSystem");
|
||||
|
||||
// Load Client spawn point //
|
||||
GameObject spawnObj = GameObject.Find("/GameSystem/ClientSpawn");
|
||||
if (spawnObj is null)
|
||||
throw new System.Exception("No ClientSpawn GameObject found under GameSystem");
|
||||
spawnPoint = spawnObj.transform.position;
|
||||
// Load clients prefabs //
|
||||
|
||||
// Load Client targets //
|
||||
targets_dict = new Dictionary<Vector2, bool>();
|
||||
GameObject targetsObj = GameObject.Find("/GameSystem/Targets");
|
||||
if (targetsObj is null)
|
||||
throw new System.Exception("No Targets GameObject found under GameSystem");
|
||||
// Find all assets labelled with 'usable' :
|
||||
// string[] guids = AssetDatabase.FindAssets("", new string[] {"Assets/Prefabs/Characters/Clients"});
|
||||
|
||||
Component[] targets = targetsObj.GetComponentsInChildren<Transform>();
|
||||
if(targets != null)
|
||||
{
|
||||
foreach(Transform target in targets)
|
||||
// foreach (string guid in guids)
|
||||
// {
|
||||
// Debug.Log(AssetDatabase.GUIDToAssetPath(guid));
|
||||
// Instantiate(guid, spawnPosition, Quaternion.identity);
|
||||
// }
|
||||
|
||||
clients = Resources.LoadAll(ClientRessourceFolder);
|
||||
|
||||
// foreach (var c in clients)
|
||||
// {
|
||||
// Debug.Log(gameObject.name+" : "+c.name + " loaded");
|
||||
// }
|
||||
if (clients.Length<nbMaxClients)
|
||||
{
|
||||
if(target.gameObject.name != "Targets")
|
||||
Debug.LogWarning("ClientManager doesn't have enough client prefab to manage unique MaxClients : "+clients.Length+"/"+nbMaxClients);
|
||||
}
|
||||
|
||||
// Load Client spawn point //
|
||||
GameObject spawnObj = GameObject.Find("/GameSystem/ClientSpawn");
|
||||
if (spawnObj is null)
|
||||
throw new System.Exception("No ClientSpawn GameObject found under GameSystem");
|
||||
spawnPoint = spawnObj.transform.position;
|
||||
|
||||
// Load Client targets //
|
||||
targets_dict = new Dictionary<Vector2, bool>();
|
||||
GameObject targetsObj = GameObject.Find("/GameSystem/Targets");
|
||||
if (targetsObj is null)
|
||||
throw new System.Exception("No Targets GameObject found under GameSystem");
|
||||
|
||||
Component[] targets = targetsObj.GetComponentsInChildren<Transform>();
|
||||
if(targets != null)
|
||||
{
|
||||
foreach(Transform target in targets)
|
||||
{
|
||||
targets_dict.Add(target.position, false);
|
||||
// Debug.Log("Client target : "+ target.gameObject.name + target.position);
|
||||
if(target.gameObject.name != "Targets")
|
||||
{
|
||||
targets_dict.Add(target.position, false);
|
||||
// Debug.Log("Client target : "+ target.gameObject.name + target.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (targets_dict.Count<nbMaxClients)
|
||||
{
|
||||
Debug.LogWarning("ClientManager doesn't have enough target to manage MaxClients : "+targets_dict.Count+"/"+nbMaxClients);
|
||||
if (targets_dict.Count<nbMaxClients)
|
||||
{
|
||||
Debug.LogWarning("ClientManager doesn't have enough target to manage MaxClients : "+targets_dict.Count+"/"+nbMaxClients);
|
||||
}
|
||||
|
||||
ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,12 +5,15 @@ using UnityEngine;
|
|||
//Define the global game system of the service. (Singleton)
|
||||
public sealed class GameSystem : MonoBehaviour
|
||||
{
|
||||
[HideInInspector]
|
||||
public bool ready = false; //Wether the GameSystems are initialized
|
||||
|
||||
//Time
|
||||
bool serviceOpen = false;
|
||||
float serviceTime = 30.0f;
|
||||
public float serviceTime = 30.0f;
|
||||
float serviceTimer = 0.0f;
|
||||
UITimer UIServiceTimer;
|
||||
float slowScale = 0.5f; //Default scale for slow mode
|
||||
public float slowScale = 0.5f; //Default scale for slow mode
|
||||
private float fixedDeltaTime;
|
||||
|
||||
//TODO : Effect on gold change
|
||||
|
@ -64,17 +67,26 @@ public sealed class GameSystem : MonoBehaviour
|
|||
//Awake is called when the script instance is being loaded.
|
||||
void Awake()
|
||||
{
|
||||
// Make a copy of the fixedDeltaTime, it defaults to 0.02f, but it can be changed in the editor
|
||||
this.fixedDeltaTime = Time.fixedDeltaTime;
|
||||
GameObject timerObj = GameObject.Find("/UI/Canvas/ServiceTimer");
|
||||
if(timerObj is null)
|
||||
if(!ready)
|
||||
{
|
||||
Debug.LogWarning("No service timer found");
|
||||
UIServiceTimer=null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UIServiceTimer=timerObj.GetComponent<UITimer>();
|
||||
// Make a copy of the fixedDeltaTime, it defaults to 0.02f, but it can be changed in the editor
|
||||
this.fixedDeltaTime = Time.fixedDeltaTime;
|
||||
GameObject timerObj = GameObject.Find("/UI/Canvas/ServiceTimer");
|
||||
if(timerObj is null)
|
||||
{
|
||||
Debug.LogWarning("No service timer found");
|
||||
UIServiceTimer=null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UIServiceTimer=timerObj.GetComponent<UITimer>();
|
||||
}
|
||||
|
||||
if(ClientManager.Instance.ready && StockManager.Instance.ready)
|
||||
{
|
||||
ready=true;
|
||||
Debug.Log("All GameSystems are ready");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,9 @@ using UnityEngine;
|
|||
//TODO : Update check stock of registered workshops
|
||||
public class StockManager : MonoBehaviour
|
||||
{
|
||||
[HideInInspector]
|
||||
public bool ready = false; //Wether the StockManager is initialized
|
||||
|
||||
//Consumable
|
||||
Dictionary<string, Sprite> consumableSprites = new Dictionary<string, Sprite>(); //Sprite associated w/ types of consumable
|
||||
HashSet<string> avail_consumable = new HashSet<string>(); //Available consumable
|
||||
|
@ -32,7 +35,7 @@ public class StockManager : MonoBehaviour
|
|||
consumableSprites[prod_name]=prod_sprite;
|
||||
updateStock(prod_name, stock);
|
||||
workshop_register.Add(workshop);
|
||||
Debug.Log(workshop.gameObject.name+" registered by StockManager");
|
||||
// Debug.Log(workshop.gameObject.name+" registered by StockManager");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,11 +74,16 @@ public class StockManager : MonoBehaviour
|
|||
//Awake is called when the script instance is being loaded.
|
||||
void Awake()
|
||||
{
|
||||
//Initialize global stock
|
||||
global_stock= new Dictionary<string, int>();
|
||||
foreach(string cons in Consumable.allowed_types)
|
||||
if(!ready)
|
||||
{
|
||||
global_stock[cons]=0;
|
||||
//Initialize global stock
|
||||
global_stock= new Dictionary<string, int>();
|
||||
foreach(string cons in Consumable.allowed_types)
|
||||
{
|
||||
global_stock[cons]=0;
|
||||
}
|
||||
|
||||
ready = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue