public void Awake() { if (_instance == null || _destroyed) { _instance = this; _destroyed = false; } else if (_instance != this) { Debug.LogError("Two instances of the same singleton '" + this + "'"); } if (_needInitialization) { _needInitialization = false; _initializedAtLeastOnce = true; #if UNITY_EDITOR || SAMPLE_OUTSIDE_EDITOR UnityEngine.Profiling.Profiler.BeginSample(_instance.name + ".Initialize"); #endif Initialize(); #if UNITY_EDITOR || SAMPLE_OUTSIDE_EDITOR UnityEngine.Profiling.Profiler.EndSample(); #endif } }
public static void Dispose() { if (_instance != null && !_destroyed) { Destroy(_instance.gameObject); _instance = null; } }
public void OnDestroy() { #if UNITY_EDITOR || SAMPLE_OUTSIDE_EDITOR UnityEngine.Profiling.Profiler.BeginSample(name + ".Destroy"); #endif Destroy(); #if UNITY_EDITOR || SAMPLE_OUTSIDE_EDITOR UnityEngine.Profiling.Profiler.EndSample(); #endif _destroyed = true; _needInitialization = true; if (setToNullAfterDestroy) { _instance = null; } }