public static void Dispose() { if (instance != null && !destroyed) { Destroy(instance.gameObject); instance = null; } }
public void OnDestroy() { Destroy(); destroyed = true; needInitialization = true; if (setToNullAfterDestroy) { instance = null; } }
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; Initialize(); } }