protected virtual void OnDestroy() { if (SingletonBehaviour.Instance == this) { SingletonBehaviour.Instance = null; } }
void Awake() { if (_instance != null) { Debug.LogError("More than one instance of a singleton detected"); return; } _instance = this; }
protected void SetInstance() { if (SingletonBehaviour.Instance != null && SingletonBehaviour.Instance != this) { this.DestroyThisBehaviour(); return; } SingletonBehaviour.Instance = this; }
/// <summary> /// 移除所有消息处理 /// </summary> public void RemoveAllMessageHands() { if (!SingletonBehaviour.isValid <Client>()) { return; } foreach (var item in _handlers) { Client.Instance.RemoveMessageParse(item.Key, this.UnpackMessage); } }
// Call this to upgrade a singleton to a persistent singleton. // This is most often done in Awake(). // This will kill an instance that tries to be a persistent singleton but isn't the current instance. public static void DontDestroyElseKill(SingletonBehaviour <T> mb) { if (mb == instance) { MonoBehaviour.DontDestroyOnLoad(instance.gameObject); } else { MonoBehaviour.Destroy(mb); } }
void Awake() { if (s_instance == null) { s_instance = this; DontDestroyOnLoad(gameObject); } else if (s_instance != this) { Destroy(gameObject); } }
private void Awake() { if (baseInstance == null) { baseInstance = this; instance = this as T; } else { Destroy(this); return; } }
// Call this to upgrade a singleton to a persistent singleton. // This is most often done in Awake(). // This will kill an instance that tries to be a persistent singleton but isn't the current instance. public static bool DontDestroyElseKill(SingletonBehaviour <T> mb) { if (mb == instance) { MonoBehaviour.DontDestroyOnLoad(instance.gameObject); return(true); } else { MonoBehaviour.Destroy(mb.gameObject); return(false); } }
// Use this for initialization protected virtual void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } // Sets this to not be destroyed when reloading scene DontDestroyOnLoad(gameObject); }
private void OnDownloading(string error, string url, float progress) { if (!string.IsNullOrEmpty(error)) { Debug.LogError(error); this.MoveNext(); return; } Debug.LogFormat("Downloading {0} percent {1}", url, progress * 100); if (progress >= 1) { SingletonBehaviour.GetInstance <ZipResource>().AddTask(new ZipResource.LoadTask(_tempUrl, _bundleUrl, (IFileItem item) => { this.MoveNext(); })); } }
protected virtual void Awake() { SingletonBehaviour.Instance = this; }