public void RemoveListen <T, U, V>(int eventType, ActRet <T, U, V> listenerBeingRemoved) { if (eventTable.ContainsKey(eventType)) { Delegate d = eventTable[eventType]; if (d == null) { Debug.LogError(string.Format("Attempting to remove listener with for event type \"{0}\" but current listener is null.", eventType)); } else if (d.GetType() != listenerBeingRemoved.GetType()) { Debug.LogError(string.Format("Attempting to remove listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being removed has type {2}", eventType, d.GetType().Name, listenerBeingRemoved.GetType().Name)); } else { // ReSharper disable once DelegateSubtraction eventTable[eventType] = (ActRet <T, U, V>)eventTable[eventType] - listenerBeingRemoved; if (eventTable[eventType] == null) { eventTable.Remove(eventType); } } } else { Debug.LogError(string.Format("Attempting to remove listener for type \"{0}\" but Messenger doesn't know about this event type.", eventType)); } }
public void AddListener <T>(int eventType, ActRet <T> listenerBeingAdded) { if (!eventTable.ContainsKey(eventType)) { eventTable.Add(eventType, null); } Delegate d = eventTable[eventType]; if (d != null && d.GetType() != listenerBeingAdded.GetType()) { Debug.LogError(string.Format("Attempting to add listener with inconsistent signature for event type {0}. Current listeners have type {1} and listener being added has type {2}", eventType, d.GetType().Name, listenerBeingAdded.GetType().Name)); } else { eventTable[eventType] = (ActRet <T>)eventTable[eventType] + listenerBeingAdded; } }