public void DisposeEventIndex(EventIndex index) { foreach (var kv in eventIndices.Where((kv) => kv.Value == index).ToArray()) { eventIndices.Remove(kv.Key); } }
private void RegisterListener(EventIndex index, IEventListener listener) { if (index == EventIndex.Null) { return; } if (!eventListeners.TryGetValue(index, out List <IEventListener> listeners)) { listeners = new List <IEventListener>(); eventListeners[index] = listeners; } listeners.Add(listener); }
private void Dispatch(EventIndex index, object eventObject) { if (index == EventIndex.Null) { return; } if (eventListeners.TryGetValue(index, out List <IEventListener> listeners)) { foreach (var listener in listeners) { listener.OnEvent(eventObject); } } }
private void UnregisterListener(EventIndex index, IEventListener listener) { if (index == EventIndex.Null) { return; } if (eventListeners.TryGetValue(index, out List <IEventListener> listeners)) { listeners.Remove(listener); if (listeners.Count == 0) { eventListeners.Remove(index); foreach (var r in eventRouters) { r.DisposeEventIndex(index); } defaultEventRouter.DisposeEventIndex(index); eventIndexPool.Destroy(index); } } }
public abstract void DisposeEventIndex(EventIndex index);