Пример #1
0
        /// <summary>
        /// Dispatch and call all the actions related to this event
        /// </summary>
        /// <param name="eventId">The event identification</param>
        /// <param name="evt">The data to be passed to the actions</param>
        public void DispatchEvent(int eventId, SimpleEvent eventData)
        {
            if (!m_EventList.ContainsKey(eventId))
            {
                return;
            }

            List <Action <SimpleEvent> > actions = m_EventList[eventId];

            if (actions == null)
            {
                return;
            }

            if (eventData != null)
            {
                eventData.m_Type = eventId;
            }

            foreach (Action <SimpleEvent> action in actions.ToArray())
            {
                if (action == null)
                {
                    continue;
                }
                action.Invoke(eventData);
                MessagingExplorerHelper.Invoke(action);
            }
        }
Пример #2
0
 /// <summary>
 /// Register one event to the dispatcher
 /// </summary>
 /// <param name="eventId">The event identification</param>
 /// <param name="evt">The action to execute when the event is dispatched</param>
 public void RegisterEvent(int eventId, Action <SimpleEvent> action)
 {
     if (!m_EventList.ContainsKey(eventId))
     {
         List <Action <SimpleEvent> > events = new List <Action <SimpleEvent> >();
         m_EventList[eventId] = events;
     }
     m_EventList[eventId].Add(action);
     MessagingExplorerHelper.Invoke(null);
 }
Пример #3
0
        /// <summary>
        /// Unregister the given event and action combination
        /// </summary>
        /// <param name="eventId">The event identification</param>
        /// <param name="action">The action to be executed when the event id dispatched</param>
        public void UnregisterEvent(int eventId, Action <SimpleEvent> action)
        {
            if (!m_EventList.ContainsKey(eventId))
            {
                return;
            }

            m_EventList[eventId].Remove(action);

            if (m_EventList[eventId].Count == 0)
            {
                m_EventList.Remove(eventId);
            }
            MessagingExplorerHelper.Invoke(null);
        }