Beispiel #1
0
        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]);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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]);
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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);
                }
            }
        }
Beispiel #6
0
 public bool Equals(TofuEvent other)
 {
     return(string.Equals(Key, other.Key));
 }