예제 #1
0
    //Inserts the event into the current queue.
    public bool QueueEvent(Events.GameEvent evt)
    {
        if (!delegates.ContainsKey(evt.GetType()))
        {
            Debug.LogWarning("EventManager: QueueEvent failed due to no listeners for event: " + evt.GetType());
            return(false);
        }

        m_eventQueue.Enqueue(evt);
        return(true);
    }
예제 #2
0
    public void TriggerEvent(Events.GameEvent e)
    {
        EventDelegate del;

        if (delegates.TryGetValue(e.GetType(), out del))
        {
            del.Invoke(e);

            // remove listeners which should only be called once
            foreach (EventDelegate k in delegates[e.GetType()].GetInvocationList())
            {
                if (onceLookups.ContainsKey(k))
                {
                    delegates[e.GetType()] -= k;

                    if (delegates[e.GetType()] == null)
                    {
                        delegates.Remove(e.GetType());
                    }

                    delegateLookup.Remove(onceLookups[k]);
                    onceLookups.Remove(k);
                }
            }
        }
        else
        {
            Debug.LogWarning("Event: " + e.GetType() + " has no listeners");
        }
    }
예제 #3
0
        public void TriggerEvent(Events.GameEvent e)
        {
            EventDelegate del;

#if UNITY_EDITOR
            Debug.Log("Event " + e.ToString() + " triggered.");
#endif

            if (delegates.TryGetValue(e.GetType(), out del))
            {
                del.Invoke(e);
#if UNITY_EDITOR
                Debug.Log("Listener " + del.Target.ToString().Split('[', ']')[1] + " invoked.");
#endif

                // remove listeners which should only be called once
                foreach (EventDelegate k in delegates[e.GetType()].GetInvocationList())
                {
                    if (onceLookups.ContainsKey(k))
                    {
                        delegates[e.GetType()] -= k;

                        if (delegates[e.GetType()] == null)
                        {
                            delegates.Remove(e.GetType());
                        }

                        delegateLookup.Remove(onceLookups[k]);
                        onceLookups.Remove(k);
                    }
                }
            }
            else
            {
                Debug.LogWarning("Event: " + e.GetType() + " has no listeners");
            }
        }