public static void Disable() { if (_instance != null) { GameObject.Destroy(_instance.gameObject); _instance = null; } }
void OnDestroy() { if (this == _instance) { _instance = null; toasts.Clear(); } }
// call Initialize() when the app loads. This will create the singleton game object. public static void Initialize() { if (_instance == null) { GameObject go = new GameObject("ToastCenter"); _instance = go.AddComponent <ToastCenter>(); // will finish initializing in OnEnable() } }
void OnEnable() { if (_instance != null && _instance != this) { Destroy(gameObject); return; } if (_instance == null) { _instance = this; _instance.InitInternal(); DontDestroyOnLoad(_instance.gameObject); } }