Add more interface w/ Unity Inspector and Managers

This commit is contained in:
Antoine H 2021-01-13 13:32:24 +01:00
parent 4f99687ae2
commit 901a2b6c10
4 changed files with 168 additions and 69 deletions

View file

@ -297,6 +297,7 @@ GameObject:
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 128722683} - component: {fileID: 128722683}
- component: {fileID: 128722684}
m_Layer: 0 m_Layer: 0
m_Name: ClientManager m_Name: ClientManager
m_TagString: Untagged m_TagString: Untagged
@ -318,6 +319,22 @@ Transform:
m_Father: {fileID: 1160225022} m_Father: {fileID: 1160225022}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &128722684
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 128722682}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2bc1593400bcb054db0179d45fa332e9, type: 3}
m_Name:
m_EditorClassIdentifier:
ready: 0
nbMaxClients: 5
clientSpawnTimer: 0.5
maxTimeNewClients: 2
--- !u!1 &156172339 --- !u!1 &156172339
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3124,7 +3141,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 1160225022} m_Father: {fileID: 1160225022}
m_RootOrder: 0 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0} m_LocalEulerAnglesHint: {x: -90, y: 0, z: 0}
--- !u!1 &357681231 --- !u!1 &357681231
GameObject: GameObject:
@ -3574,6 +3591,50 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 6 m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &722742920
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 722742921}
- component: {fileID: 722742922}
m_Layer: 0
m_Name: StockManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &722742921
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 722742920}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.8086959, y: -2.008171, z: 1.1246597}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1160225022}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &722742922
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 722742920}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f33c46360b013aa48a333f4be9bb3c09, type: 3}
m_Name:
m_EditorClassIdentifier:
ready: 0
--- !u!1001 &728581040 --- !u!1001 &728581040
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -7717,6 +7778,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5f18e7df2f912f644a6a6949b25117b6, type: 3} m_Script: {fileID: 11500000, guid: 5f18e7df2f912f644a6a6949b25117b6, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
ready: 0
serviceTime: 60
slowScale: 0.5
--- !u!4 &1160225022 --- !u!4 &1160225022
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -7728,8 +7792,9 @@ Transform:
m_LocalPosition: {x: -0.21348187, y: 4.0925093, z: -2.1510859} m_LocalPosition: {x: -0.21348187, y: 4.0925093, z: -2.1510859}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 322056904} - {fileID: 722742921}
- {fileID: 128722683} - {fileID: 128722683}
- {fileID: 322056904}
- {fileID: 1863361785} - {fileID: 1863361785}
- {fileID: 1486551544} - {fileID: 1486551544}
m_Father: {fileID: 0} m_Father: {fileID: 0}
@ -7976,7 +8041,7 @@ Transform:
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1} m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
m_Children: [] m_Children: []
m_Father: {fileID: 1160225022} m_Father: {fileID: 1160225022}
m_RootOrder: 3 m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1520733216 --- !u!1 &1520733216
GameObject: GameObject:
@ -32996,7 +33061,7 @@ Transform:
- {fileID: 238532360} - {fileID: 238532360}
- {fileID: 1653625651} - {fileID: 1653625651}
m_Father: {fileID: 1160225022} m_Father: {fileID: 1160225022}
m_RootOrder: 2 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1905354803 --- !u!1 &1905354803
GameObject: GameObject:

View file

@ -6,10 +6,13 @@ using UnityEditor;
//Define the system managing the clients. (Singleton) //Define the system managing the clients. (Singleton)
public sealed class ClientManager : MonoBehaviour 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; bool clientSpawnReady = false;
float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that) public float clientSpawnTimer = 0.5f; //Intial time before first spawn (pseudo-random after that)
float maxTimeNewClients = 2.0f; public float maxTimeNewClients = 2.0f; //Longest waiting time for new clients
string ClientRessourceFolder = "Clients"; string ClientRessourceFolder = "Clients";
private Object[] clients; private Object[] clients;
@ -53,6 +56,12 @@ public sealed class ClientManager : MonoBehaviour
Destroy(client); Destroy(client);
// Debug.Log(client.name+" destroyed"+clientIDs.Count); // 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. //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. //Awake is called when the script instance is being loaded.
void Awake() void Awake()
{ {
ClientContainer = GameObject.Find("/GameSystem/ClientManager"); if(!ready)
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)
{ {
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 // // Load clients prefabs //
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 // // Find all assets labelled with 'usable' :
targets_dict = new Dictionary<Vector2, bool>(); // string[] guids = AssetDatabase.FindAssets("", new string[] {"Assets/Prefabs/Characters/Clients"});
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>(); // foreach (string guid in guids)
if(targets != null) // {
{ // Debug.Log(AssetDatabase.GUIDToAssetPath(guid));
foreach(Transform target in targets) // 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); if(target.gameObject.name != "Targets")
// Debug.Log("Client target : "+ target.gameObject.name + target.position); {
targets_dict.Add(target.position, false);
// Debug.Log("Client target : "+ target.gameObject.name + target.position);
}
} }
} }
} if (targets_dict.Count<nbMaxClients)
if (targets_dict.Count<nbMaxClients) {
{ Debug.LogWarning("ClientManager doesn't have enough target to manage MaxClients : "+targets_dict.Count+"/"+nbMaxClients);
Debug.LogWarning("ClientManager doesn't have enough target to manage MaxClients : "+targets_dict.Count+"/"+nbMaxClients); }
ready = true;
} }
} }

View file

@ -5,12 +5,15 @@ using UnityEngine;
//Define the global game system of the service. (Singleton) //Define the global game system of the service. (Singleton)
public sealed class GameSystem : MonoBehaviour public sealed class GameSystem : MonoBehaviour
{ {
[HideInInspector]
public bool ready = false; //Wether the GameSystems are initialized
//Time //Time
bool serviceOpen = false; bool serviceOpen = false;
float serviceTime = 30.0f; public float serviceTime = 30.0f;
float serviceTimer = 0.0f; float serviceTimer = 0.0f;
UITimer UIServiceTimer; UITimer UIServiceTimer;
float slowScale = 0.5f; //Default scale for slow mode public float slowScale = 0.5f; //Default scale for slow mode
private float fixedDeltaTime; private float fixedDeltaTime;
//TODO : Effect on gold change //TODO : Effect on gold change
@ -64,17 +67,26 @@ public sealed class GameSystem : MonoBehaviour
//Awake is called when the script instance is being loaded. //Awake is called when the script instance is being loaded.
void Awake() void Awake()
{ {
// Make a copy of the fixedDeltaTime, it defaults to 0.02f, but it can be changed in the editor if(!ready)
this.fixedDeltaTime = Time.fixedDeltaTime;
GameObject timerObj = GameObject.Find("/UI/Canvas/ServiceTimer");
if(timerObj is null)
{ {
Debug.LogWarning("No service timer found"); // Make a copy of the fixedDeltaTime, it defaults to 0.02f, but it can be changed in the editor
UIServiceTimer=null; this.fixedDeltaTime = Time.fixedDeltaTime;
} GameObject timerObj = GameObject.Find("/UI/Canvas/ServiceTimer");
else if(timerObj is null)
{ {
UIServiceTimer=timerObj.GetComponent<UITimer>(); 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");
}
} }
} }

View file

@ -6,6 +6,9 @@ using UnityEngine;
//TODO : Update check stock of registered workshops //TODO : Update check stock of registered workshops
public class StockManager : MonoBehaviour public class StockManager : MonoBehaviour
{ {
[HideInInspector]
public bool ready = false; //Wether the StockManager is initialized
//Consumable //Consumable
Dictionary<string, Sprite> consumableSprites = new Dictionary<string, Sprite>(); //Sprite associated w/ types of consumable Dictionary<string, Sprite> consumableSprites = new Dictionary<string, Sprite>(); //Sprite associated w/ types of consumable
HashSet<string> avail_consumable = new HashSet<string>(); //Available consumable HashSet<string> avail_consumable = new HashSet<string>(); //Available consumable
@ -32,7 +35,7 @@ public class StockManager : MonoBehaviour
consumableSprites[prod_name]=prod_sprite; consumableSprites[prod_name]=prod_sprite;
updateStock(prod_name, stock); updateStock(prod_name, stock);
workshop_register.Add(workshop); 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. //Awake is called when the script instance is being loaded.
void Awake() void Awake()
{ {
//Initialize global stock if(!ready)
global_stock= new Dictionary<string, int>();
foreach(string cons in Consumable.allowed_types)
{ {
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;
} }
} }