Ejemplo n.º 1
0
        public void TriggerEvent(VSGameEvent vSGameEvent)
        {
            EventDelegate del;

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

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

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

                        delegateLookup.Remove(onceLookups[k]);
                        onceLookups.Remove(k);
                    }
                }
            }
            else
            {
                Debug.LogWarning("Event: " + vSGameEvent.GetType() + " has no listeners");
            }
        }
Ejemplo n.º 2
0
        public bool QueueEvent(VSGameEvent evt)
        {
            if (!delegates.ContainsKey(evt.GetType()))
            {
                Debug.LogWarning("EventManager: QueueEvent failed due to no listeners for event: " + evt.GetType());
                return(false);
            }

            mEventQueue.Enqueue(evt);
            return(true);
        }
Ejemplo n.º 3
0
        void Update()
        {
            float timer = 0.0f;

            while (mEventQueue.Count > 0)
            {
                if (mLimitQueueProcTime)
                {
                    if (timer > mQueueProcTime)
                    {
                        return;
                    }
                }

                VSGameEvent evt = mEventQueue.Dequeue() as VSGameEvent;
                TriggerEvent(evt);

                if (mLimitQueueProcTime)
                {
                    timer += Time.deltaTime;
                }
            }
        }