Exemplo n.º 1
0
        /// <summary>
        /// Initializes the singleton
        /// </summary>
        void Start()
        {
            if (s_Instance == null)
            {
                s_Instance = this;
            }
            else
            {
                Destroy(this);
                return;
            }

            DontDestroyOnLoad(gameObject);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Destroys the singleton
 /// </summary>
 void OnDestroy()
 {
     if (s_Instance == this)
     {
         s_Instance = null;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Removes the instance of the DebugUtils if the instance being destroyed is the the same as the singleton.
 /// </summary>
 /// <param name="aInstance">The instance to destroy</param>
 private static void DestroyInstance(DebugUtils aInstance)
 {
     if (s_Instance == aInstance)
     {
         s_Instance = null;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets the instance of the DebugUtils to the instance given.
 /// </summary>
 /// <param name="aInstance">The instance to make singleton</param>
 /// <returns></returns>
 private static bool SetInstance(DebugUtils aInstance)
 {
     if (s_Instance != null && s_Instance != aInstance)
     {
         return false;
     }
     s_Instance = aInstance;
     return true;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Creates an instance of the DebugUtils if it was missing.
 /// </summary>
 private static void CreateInstance()
 {
     GameObject persistant = GameObject.Find(Game.PERSISTANT_GAME_OBJECT_NAME);
     if (persistant == null)
     {
         persistant = new GameObject(Game.PERSISTANT_GAME_OBJECT_NAME);
         persistant.transform.position = Vector3.zero;
         persistant.transform.rotation = Quaternion.identity;
     }
     s_Instance = persistant.GetComponent<DebugUtils>();
     if (s_Instance == null)
     {
         s_Instance = persistant.AddComponent<DebugUtils>();
     }
 }