protected virtual void OnDestroy() { if (persistent) { GenericEvent.RemoveListener(this, Key); } }
protected virtual void OnDisable() { if (!persistent) { GenericEvent.RemoveListener(this, Key); } }
public static void StopListening(string eventName, UnityAction <T, U, X> listener) { if (eventManager == null) { return; } GenericEvent <T, U, X> thisEvent = null; if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.RemoveListener(listener); } }
public void StopListening <T>(string eventName, UnityAction <T> listener) { Dictionary <string, GenericEvent <T> > typeDictionary = null; object baseDict = null; if (eventDictionaryType.TryGetValue(typeof(T), out baseDict)) { typeDictionary = baseDict as Dictionary <string, GenericEvent <T> >; } else { return; } GenericEvent <T> thisEvent = null; if (typeDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.RemoveListener(listener); } }
/// <summary> /// 去除事件 /// </summary> /// <param name="eventEnumType"></param> /// <param name="eventName"></param> /// <param name="listener"></param> public static void RemoveListener(GenericEventEnumType eventEnumType, string eventName, GenericEvent_CallBack listener) { switch (eventEnumType) { case GenericEventEnumType.Generic: if (genericEvent != null) { genericEvent.RemoveListener(eventName, listener); } break; case GenericEventEnumType.Message: if (messageEvent != null) { messageEvent.RemoveListener(eventName, listener); } break; default: break; } }
public static void AddCleanGenericListener <T>(this GenericEvent <T> @event, UnityAction <T> action) { @event.RemoveListener(action); @event.AddListener(action); }