public TofuEvent Get(EventKey key) { if (!IsRegistered(key)) { //Debug.Log("No event registered for " + name + ", creating one"); TofuEvent evnt = new TofuEvent(key); _events.Add(key, evnt); return(evnt); } return(_events[key]); }
public void ContextBindEventListener(TofuEvent evnt, IListener listener) { if (listener == this) { Debug.LogWarning("Trying to bind EventContext as its own listener."); } if (!_eventListeners.ContainsKey(evnt)) { _eventListeners.Add(evnt, new HashSet <IListener>()); } _eventListeners[evnt].Add(listener); }
public TofuEvent Get(dynamic key) { string keyString = key.ToString(); if (!IsRegistered(keyString)) { //Debug.Log("No event registered for " + name + ", creating one"); TofuEvent evnt = new TofuEvent(keyString); _events.Add(keyString, evnt); return(evnt); } return(_events[keyString]); }
public void ContextRemoveEventListener(TofuEvent evnt, IListener listener) { if (!_eventListeners.ContainsKey(evnt) || !_eventListeners[evnt].Contains(listener)) { //Debug.Log("Not bound."); return; } if (_eventListenersToRemove == null) { _eventListenersToRemove = new Dictionary <TofuEvent, IListener>(); } if (!_eventListenersToRemove.ContainsKey(evnt)) { _eventListenersToRemove.Add(evnt, listener); } }
public void TriggerEvent(EventKey eventKey, EventPayload payload) { if (EventPayloadLibrary != null) { if (eventKey == EventKey.None) { throw new ArgumentException("Cannot trigger a null event!"); } if (!EventPayloadLibrary.ValidatePayload(payload)) { throw new ArgumentException("Invalid payload!"); } } FlushListeners(); TofuEvent evnt = GetEvent(eventKey); if (!_eventListeners.ContainsKey(evnt) || _eventListeners[evnt].Count == 0) { return; } _events.Get(evnt.Key).HasBeenCalled(); List <IListener> listeners = new List <IListener>(_eventListeners[evnt]); foreach (IListener listener in listeners) { listener.ReceiveEvent(evnt, payload); } if (EventLogger != null) { if (payload == null) { EventLogger.LogEvent(Time.time, eventKey, "NULL"); } else { EventLogger.LogEvent(Time.time, eventKey, payload.ContentType); } } }
public bool Equals(TofuEvent other) { return(string.Equals(Key, other.Key)); }