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 UnityEditor;
//Define the system managing the clients. (Singleton)
//TODO: Switch to a registering approach for clients
public sealed class ClientManager : MonoBehaviour
{
public static string ClientManager_path="/GameSystem/ClientManager";
//Singleton
private static ClientManager _instance=null;
public static ClientManager Instance { get
{
if(_instance is null)
Debug.LogError("Missing ClientManager instance");
if(_instance is null) //Force Awakening if needed
GameObject.Find(ClientManager_path).GetComponent<ClientManager>().Awake();
return _instance;
}
}
@ -139,7 +141,7 @@ public sealed class ClientManager : MonoBehaviour
if(!ready)
{
ClientContainer = GameObject.Find("/GameSystem/ClientManager");
ClientContainer = GameObject.Find(ClientManager_path);
if (ClientContainer is null)
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
public sealed class EventManager : MonoBehaviour
{
public static string EventManager_path="/GameSystem/EventManager";
//Singleton
private static EventManager _instance=null;
public static EventManager Instance { get
{
if(_instance is null)
Debug.LogError("Missing EventManager instance");
if(_instance is null) //Force Awakening if needed
GameObject.Find(EventManager_path).GetComponent<EventManager>().Awake();
return _instance;
}
}
@ -111,7 +112,7 @@ public sealed class EventManager : MonoBehaviour
if(!ready)
{
EventContainer = GameObject.Find("/GameSystem/EventManager");
EventContainer = GameObject.Find(EventManager_path);
if (EventContainer is null)
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)
public sealed class GameSystem : MonoBehaviour
{
public static string GameSystem_path="/GameSystem";
//Singleton
private static GameSystem _instance=null;
public static GameSystem Instance { get
{
if(_instance is null)
Debug.LogError("Missing GameSystem instance");
if(_instance is null) //Force Awakening if needed
GameObject.Find(GameSystem_path).GetComponent<GameSystem>().Awake();
return _instance;
}
}

View file

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