internal void Dispatch() { if (!this.IsAlive) { Destroy(); return; } int index = 0; while (index < _listenerList.Count) { ListenerObject listener = _listenerList[index]; if (listener.IsAlive) { listener.Callback(this); index++; } else { UnregisterEventListenerObject(listener); } } if (_listenerList.Count <= 0) { Destroy(); } }
internal void UnregisterEventListenerObject(ListenerObject aListener) { if (aListener != null && _listenerList.Contains(aListener)) { _listenerList.Remove(aListener); } }
internal void RegisterEventListener(object aListener, Action <EventObject> aMethod, int aPriority = 1) { ListenerObject listener = new ListenerObject(aListener, aMethod, aPriority); _listenerList.Add(listener); _listenerList = _listenerList.OrderBy(o => o.Priority).ToList <ListenerObject>(); }
internal void UnregisterEventListener(object aListener, Action <EventObject> aMethod = null) { int index = 0; bool eventRemoved = false; while (!eventRemoved) { if (index >= _listenerList.Count) { break; } ListenerObject listener = _listenerList[index]; if ((listener.ObjectReference.Equals(aListener) && aMethod != null && listener.Callback.Equals(aMethod)) || (listener.ObjectReference.Equals(aListener) && aMethod == null)) { UnregisterEventListenerObject(listener); eventRemoved = true; } else { if (listener.IsAlive) { index++; } else { UnregisterEventListenerObject(listener); } } } if (!eventRemoved) { string prefix = ""; if (aMethod != null) { prefix += "The method [" + aMethod.ToString() + "] from "; } Debug.LogWarning("[EventObject.cs] - UnregisterEventListener() - " + prefix + aListener.ToString() + "] doesn't seem to be registered for the event: " + _event + "."); } if (_listenerList.Count <= 0) { Destroy(); } }