private void OnDisable()
 {
     if (persistentSingletonInstance == this)
     {
         persistentSingletonInstance = null;
     }
 }
        private void OnEnable()
        {
            // Don't allow more than one PersistentSingleton instance.
            // This makes accessing the PersistentSingleton via a cached instance simpler, and
            // helps with making sure there are no memory leaks (since we are using
            // the DontSave hideFlag, to keep the ScriptableObject from being unloaded
            // during assembly reloading etc.).
            if (persistentSingletonInstance == null)
            {
                                #if DEV_MODE && DEBUG_ENABLED
                Debug.Log("PersistentSingleton - OnEnable");
                                #endif

                persistentSingletonInstance = this;
                Setup();
            }
            else if (persistentSingletonInstance != this)
            {
                                #if DEV_MODE
                Debug.LogError("Destroying PersistentSingleton instance because one already existed; there can only be one.");
                                #endif
                if (Application.isPlaying)
                {
                    Destroy(this);
                }
                else
                {
                    DestroyImmediate(this);
                }
            }
        }
Esempio n. 3
0
        /// <summary> Gets target that the int represents. </summary>
        /// <returns> The target. </returns>
        public static Object GetTarget(int data)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            UnityEngine.Debug.Assert(PersistentSingleton.Ready || PersistentSingleton.Exists <ObjectIds>(), "GetTarget called with with PersistentSingleton not ready and ObjectIds instance not yet existing");
                        #endif

            return(Instance().GetTargetInternal(data));
        }
Esempio n. 4
0
 private static ObjectIds Instance()
 {
     if (instance == null)
     {
         instance = PersistentSingleton.Get <ObjectIds>();
         if (instance != null)
         {
             instance.Setup(0);
         }
     }
     return(instance);
 }
Esempio n. 5
0
 public static Editors Instance()
 {
     if (instance == null)
     {
         instance = PersistentSingleton.Get <Editors>();
         if (instance != null)
         {
             instance.Setup(0);
         }
                         #if DEV_MODE
         else if (!ApplicationUtility.IsQuitting)
         {
             Debug.LogWarning("Editors.Instance() returning null!");
         }
                         #endif
     }
     return(instance);
 }
 private static PersistentSingleton Instance()
 {
     if (persistentSingletonInstance == null)
     {
         if (ApplicationUtility.IsQuitting)
         {
                                 #if DEV_MODE && DEBUG_ENABLED
             Debug.LogWarning("PersistentSingleton.Instance returning null because applicationIsQuitting");
                                 #endif
             return(null);
         }
         persistentSingletonInstance = FindOrCreateScriptableObject <PersistentSingleton>();
         if (!persistentSingletonInstance.setupInProgressOrDone)
         {
             persistentSingletonInstance.Setup();
         }
     }
     return(persistentSingletonInstance);
 }