Force awakening if needed for Singleton

This commit is contained in:
Antoine H 2021-01-19 10:46:07 +01:00
parent a940cb64ba
commit aa850a7c0b
4 changed files with 15 additions and 10 deletions

View file

@ -3,16 +3,18 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
//Define the system managing the clients. (Singleton) //Define the system managing the clients. (Singleton)
//TODO: Switch to a registering approach for clients //TODO: Switch to a registering approach for clients
public sealed class ClientManager : MonoBehaviour public sealed class ClientManager : MonoBehaviour
{ {
public static string ClientManager_path="/GameSystem/ClientManager";
//Singleton //Singleton
private static ClientManager _instance=null; private static ClientManager _instance=null;
public static ClientManager Instance { get public static ClientManager Instance { get
{ {
if(_instance is null) if(_instance is null) //Force Awakening if needed
Debug.LogError("Missing ClientManager instance"); GameObject.Find(ClientManager_path).GetComponent<ClientManager>().Awake();
return _instance; return _instance;
} }
} }
@ -139,7 +141,7 @@ public sealed class ClientManager : MonoBehaviour
if(!ready) if(!ready)
{ {
ClientContainer = GameObject.Find("/GameSystem/ClientManager"); ClientContainer = GameObject.Find(ClientManager_path);
if (ClientContainer is null) if (ClientContainer is null)
throw new System.Exception("No ClientManager found under GameSystem"); throw new System.Exception("No ClientManager found under GameSystem");

View file

@ -7,12 +7,13 @@ using UnityEngine.AI;
//TODO: Switch to a registering approach for events //TODO: Switch to a registering approach for events
public sealed class EventManager : MonoBehaviour public sealed class EventManager : MonoBehaviour
{ {
public static string EventManager_path="/GameSystem/EventManager";
//Singleton //Singleton
private static EventManager _instance=null; private static EventManager _instance=null;
public static EventManager Instance { get public static EventManager Instance { get
{ {
if(_instance is null) if(_instance is null) //Force Awakening if needed
Debug.LogError("Missing EventManager instance"); GameObject.Find(EventManager_path).GetComponent<EventManager>().Awake();
return _instance; return _instance;
} }
} }
@ -111,7 +112,7 @@ public sealed class EventManager : MonoBehaviour
if(!ready) if(!ready)
{ {
EventContainer = GameObject.Find("/GameSystem/EventManager"); EventContainer = GameObject.Find(EventManager_path);
if (EventContainer is null) if (EventContainer is null)
throw new System.Exception("No EventManager found under GameSystem"); throw new System.Exception("No EventManager found under GameSystem");

View file

@ -5,12 +5,13 @@ 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
{ {
public static string GameSystem_path="/GameSystem";
//Singleton //Singleton
private static GameSystem _instance=null; private static GameSystem _instance=null;
public static GameSystem Instance { get public static GameSystem Instance { get
{ {
if(_instance is null) if(_instance is null) //Force Awakening if needed
Debug.LogError("Missing GameSystem instance"); GameObject.Find(GameSystem_path).GetComponent<GameSystem>().Awake();
return _instance; return _instance;
} }
} }

View file

@ -6,12 +6,13 @@ using UnityEngine;
//TODO : Update check stock of registered workshops //TODO : Update check stock of registered workshops
public sealed class StockManager : MonoBehaviour public sealed class StockManager : MonoBehaviour
{ {
public static string StockManager_path="/GameSystem/StockManager";
//Singleton //Singleton
private static StockManager _instance=null; private static StockManager _instance=null;
public static StockManager Instance { get public static StockManager Instance { get
{ {
if(_instance is null) if(_instance is null) //Force Awakening if needed
Debug.LogError("Missing StockManager instance"); GameObject.Find(StockManager_path).GetComponent<StockManager>().Awake();
return _instance; return _instance;
} }
} }