public void RemoveEventListener(enEventID enEventId, OnEventHandler onEventHandler) { if (m_eventMap[(int)enEventId] != null) { m_eventMap[(int)enEventId] = (OnEventHandler)Delegate.Remove(m_eventMap[(int)enEventId], onEventHandler); } }
public void DispathEvent(enEventID eventId) { Event @event = GetEvent(); @event.EnEventId = eventId; DispathEvent(@event); }
private void HandleEvent(object sender, T e) { enEventID eventId = e.EventID; bool noHandlerException = false; if (eventHandlers.TryGetValue(eventId, out var handlers) && handlers.Count > 0) { LinkedListNode <EventHandler <T> > current = handlers.First; while (current != null) { LinkedListNode <EventHandler <T> > next = current.Next; current.Value(sender, e); current = next; } } else if (defaultHandler != null) { defaultHandler(sender, e); } else if ((eventPoolMode & enEventPoolMode.AllowNoHandler) == 0) { noHandlerException = true; } ReferencePool.ReferencePool.Release <T>(e); if (noHandlerException) { Debuger.LogError(Utility.StringUtility.Format("Event '{0}' not allow no handler.", eventId.ToString())); } }
public void DispathEvent(enEventID enEventId, stEventParms stEventParms) { Event @event = GetEvent(); @event.EnEventId = enEventId; @event.StEventParms = stEventParms; DispathEvent(@event); }
public int Count(enEventID id) { if (eventHandlers.TryGetValue(id, out var handlers)) { return(handlers.Count); } return(0); }
public bool Check(enEventID id, EventHandler <T> handler) { if (handler == null) { Debuger.LogError("Event handler is invalid."); } if (!eventHandlers.TryGetValue(id, out var handlers)) { return(false); } return(handlers.Contains(handler)); }
public void AddEventListener(enEventID enEventId, OnEventHandler onEventHandler) { if (m_eventMap[(int)enEventId] == null) { m_eventMap[(int)enEventId] = delegate { }; m_eventMap[(int)enEventId] = (OnEventHandler)Delegate.Combine(m_eventMap[(int)enEventId], onEventHandler); } else { //加之前先移除 防止一个方法执行多次 m_eventMap[(int)enEventId] = (OnEventHandler)Delegate.Remove(m_eventMap[(int)enEventId], onEventHandler); m_eventMap[(int)enEventId] = (OnEventHandler)Delegate.Combine(m_eventMap[(int)enEventId], onEventHandler); } }
public void Unsubscribe(enEventID id, EventHandler <T> handler) { if (handler == null) { Debuger.LogError("Event handler is invalid."); } if (!eventHandlers.TryGetValue(id, out var handlers)) { Debuger.LogError(Utility.StringUtility.Format("Event '{0}' not exists any handler.", id.ToString())); } if (!handlers.Remove(handler)) { Debuger.LogError(Utility.StringUtility.Format("Event '{0}' not exists specified handler.", id.ToString())); } }
public void Subscribe(enEventID id, EventHandler <T> handler) { if (!eventHandlers.TryGetValue(id, out var handlers)) { handlers = new LinkedList <EventHandler <T> >(); handlers.AddLast(handler); eventHandlers.Add(id, handlers); } else if ((eventPoolMode & enEventPoolMode.AllowMultiHandler) == 0) { Debuger.LogError(Utility.StringUtility.Format("Event '{0}' not allow multi handler.", id.ToString())); } else if ((eventPoolMode & enEventPoolMode.AllowDuplicateHandler) == 0 && Check(id, handler)) { Debuger.LogError(Utility.StringUtility.Format("Event '{0}' not allow duplicate handler.", id.ToString())); } else { handlers.AddLast(handler); } }
public bool HasEventListener(enEventID enEventId) { return(m_eventMap[(int)enEventId] == null); }
public void Unsubscribe(enEventID id, EventHandler <GameEventArgs> handler) { eventPool.Unsubscribe(id, handler); }
public bool Check(enEventID id, EventHandler <GameEventArgs> handler) { return(eventPool.Check(id, handler)); }
public int Count(enEventID id) { return(eventPool.Count(id)); }
public void Clear() { m_isused = false; EnEventId = enEventID.None; }