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");