/// <summary> /// 添加事件 /// </summary> /// <param name="eventEnumType"></param> /// <param name="eventName"></param> /// <param name="eventCall"></param> public static GenericEvent_CallBack AddListener(GenericEventEnumType eventEnumType, string eventName, GenericEvent_CallBack listener) { GenericEvent_CallBack _listener = listener; switch (eventEnumType) { case GenericEventEnumType.Generic: if (genericEvent != null) { _listener = genericEvent.AddListener(eventName, listener); } break; case GenericEventEnumType.Message: if (messageEvent != null) { _listener = messageEvent.AddListener(eventName, listener); } break; default: break; } return(_listener); }
protected virtual void Awake() { if (persistent) { GenericEvent.AddListener(this, Key); } }
protected virtual void OnEnable() { if (!persistent) { GenericEvent.AddListener(this, Key); } }
public void StartListening <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 { typeDictionary = new Dictionary <string, GenericEvent <T> >(); eventDictionaryType.Add(typeof(T), typeDictionary); } GenericEvent <T> thisEvent = null; if (typeDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.AddListener(listener); } else { thisEvent = new GenericEvent <T>(); thisEvent.AddListener(listener); typeDictionary.Add(eventName, thisEvent); } }
public void SubscribeToEvent(string eventName, UnityAction <Hashtable> listener) { if (genericEventsList.ContainsKey(eventName)) { genericEventsList[eventName].AddListener(listener); } else { GenericEvent gEvent = new GenericEvent(); gEvent.AddListener(listener); genericEventsList.Add(eventName, gEvent); } }
public static void Subscribe(string eventName, UnityAction <object[]> listener) { UnityEvent <object[]> thisEvent = null; if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.AddListener(listener); } else { thisEvent = new GenericEvent(); thisEvent.AddListener(listener); instance.eventDictionary.Add(eventName, thisEvent); } }
public static void StartListening(string eventName, UnityAction <T, U, X> listener) { GenericEvent <T, U, X> thisEvent = null; if (instance.eventDictionary.TryGetValue(eventName, out thisEvent)) { thisEvent.AddListener(listener); } else { thisEvent = new GenericEvent <T, U, X>(); thisEvent.AddListener(listener); instance.eventDictionary.Add(eventName, thisEvent); } }
public static void AddCleanGenericListener <T>(this GenericEvent <T> @event, UnityAction <T> action) { @event.RemoveListener(action); @event.AddListener(action); }