public static void AddListener <MMEvent>(DHEventListener <MMEvent> listener) where MMEvent : struct { Type eventType = typeof(MMEvent); if (!_subscribersList.ContainsKey(eventType)) { _subscribersList[eventType] = new List <DHEventListenerBase>(); } if (!SubscriptionExists(eventType, listener)) { _subscribersList[eventType].Add(listener); } }
public static void RemoveListener <MMEvent>(DHEventListener <MMEvent> listener) where MMEvent : struct { Type eventType = typeof(MMEvent); if (!_subscribersList.ContainsKey(eventType)) { #if EVENTROUTER_THROWEXCEPTIONS throw new ArgumentException(string.Format("Removing listener \"{0}\", but the event type \"{1}\" isn't registered.", listener, eventType.ToString())); #else return; #endif } List <DHEventListenerBase> subscriberList = _subscribersList[eventType]; bool listenerFound; listenerFound = false; if (listenerFound) { } for (int i = 0; i < subscriberList.Count; i++) { if (subscriberList[i] == listener) { subscriberList.Remove(subscriberList[i]); listenerFound = true; if (subscriberList.Count == 0) { _subscribersList.Remove(eventType); } return; } } #if EVENTROUTER_THROWEXCEPTIONS if (!listenerFound) { throw new ArgumentException(string.Format("Removing listener, but the supplied receiver isn't subscribed to event type \"{0}\".", eventType.ToString())); } #endif }
public static void MMEventStopListening <EventType>(this DHEventListener <EventType> caller) where EventType : struct { MMEventManager.RemoveListener <EventType>(caller); }