void OnDestroy() { // reset this static var to null if it's the singleton instance if (s_instance == this) { ClearAllListener(); s_instance = null; } }
void Awake() { // check if there's another instance already exist in scene if (s_instance != null && s_instance.GetInstanceID() != this.GetInstanceID()) { // Destroy this instances because already exist the singleton of EventsDispatcer Common.Log("An instance of EventDispatcher already exist : <{1}>, So destroy this instance : <{2}>!!", s_instance.name, name); Destroy(gameObject); } else { // set instance s_instance = this as ObserverEventDispatcher; } }