Exemplo n.º 1
0
        private IEnumerator FireEventRoutine(EventInfoBase eventInfo, Type trueEventInfoClass)
        {
            object[] param = new object[1] {
                eventInfo
            };

            if (globalEventListeners.ContainsKey(trueEventInfoClass))
            {
                foreach (Tuple <MethodInfo, object> tuple in globalEventListeners[trueEventInfoClass])
                {
                    tuple.Item1.Invoke(tuple.Item2, param);
                }
            }

            if (unityEventListeners == null)
            {
                yield break;
            }
            if (!unityEventListeners.ContainsKey(trueEventInfoClass))
            {
                yield break;
            }

            foreach (UnityEventEventInfo unityEventInfo in unityEventListeners[trueEventInfoClass])
            {
                unityEventInfo.Invoke(eventInfo);
            }

            yield return(null);
        }
 /// <summary>
 /// Fires an event of type EventInfoParameter ONLY to the components on this game object
 /// who have subscribed
 /// </summary>
 /// <param name="eventInfo"></param>
 public void FireLocalEvent(EventInfoBase eventInfo)
 {
     if (!enabled)
     {
         return;
     }
     StartCoroutine(Fire(eventInfo));
     StartCoroutine(FireUnityEvents(eventInfo));
 }
Exemplo n.º 3
0
        public void FireGlobalEvent(EventInfoBase eventInfo)
        {
            System.Type trueEventInfoClass = eventInfo.GetType();

            if ((globalEventListeners == null || !globalEventListeners.ContainsKey(trueEventInfoClass)) &&
                (unityEventListeners == null || !unityEventListeners.ContainsKey(trueEventInfoClass)))
            {
                // No one is listening, we are done.
                return;
            }

            StartCoroutine(FireEventRoutine(eventInfo, trueEventInfoClass));
        }
        private IEnumerator FireUnityEvents(EventInfoBase eventInfo)
        {
            System.Type trueEventInfoClass = eventInfo.GetType();

            if (unityEventListeners == null)
            {
                yield break;
            }

            foreach (Dictionary <System.Type, List <UnityEventEventInfo> > eventListeners in unityEventListeners.Values)
            {
                if (!eventListeners.ContainsKey(trueEventInfoClass) || eventListeners[trueEventInfoClass] == null)
                {
                    // No one is listening, we are done.
                    continue;
                }

                foreach (UnityEventEventInfo el in eventListeners[trueEventInfoClass])
                {
                    el.Invoke(eventInfo);
                }
            }
            yield return(null);
        }
        private IEnumerator Fire(EventInfoBase eventInfo)
        {
            System.Type trueEventInfoClass = eventInfo.GetType();

            if (instanceEventListeners == null)
            {
                yield break;
            }

            foreach (Dictionary <System.Type, List <LocalEventListener> > eventListeners in instanceEventListeners.Values)
            {
                if (!eventListeners.ContainsKey(trueEventInfoClass) || eventListeners[trueEventInfoClass] == null)
                {
                    // No one is listening, we are done.
                    continue;
                }

                foreach (LocalEventListener el in eventListeners[trueEventInfoClass])
                {
                    el(eventInfo);
                }
            }
            yield return(null);
        }