using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; //Define the system managing the clients. (Singleton) public sealed class ClientManager : MonoBehaviour { [HideInInspector] public bool ready = false; //Wether the ClientManager is initialized public int nbMaxClients = 3; bool clientSpawnReady = false; 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; GameObject ClientContainer = null; List clientIDs = new List(); Vector2 spawnPoint; Dictionary targets_dict; //Dict with target and wether they're taken by a client //Request new client //Return wether a new client was created public bool clientRequest() { if(clientSpawnReady && clientIDs.Count avail_tgt = new List(); foreach(KeyValuePair tgt in targets_dict) if(tgt.Value is false) avail_tgt.Add(tgt.Key); Vector2 target = avail_tgt[Random.Range(0, avail_tgt.Count)]; targets_dict[target]=true; return target; } } //Return a random order from available consummable //TODO : Check stock before assignement ? public string assignOrder() { List available_types = new List(Consumable.allowed_types); string order_type = available_types[Random.Range(0, available_types.Count)]; return order_type; } //Awake is called when the script instance is being loaded. void Awake() { if(!ready) { 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(); GameObject targetsObj = GameObject.Find("/GameSystem/Targets"); if (targetsObj is null) throw new System.Exception("No Targets GameObject found under GameSystem"); Component[] targets = targetsObj.GetComponentsInChildren(); if(targets != null) { foreach(Transform target in targets) { if(target.gameObject.name != "Targets") { targets_dict.Add(target.position, false); // Debug.Log("Client target : "+ target.gameObject.name + target.position); } } } if (targets_dict.Count(); } //// }