Exemplo n.º 1
0
 /// <summary>
 /// Attaches a delegate to the BroadcastListener, which listens for all game events.
 /// </summary>
 public static void RegisterAll(GameEventCallback <IGameEvent> f)
 {
     _allEventListeners.Add(new GOCallbackPair(
                                ((MonoBehaviour)f.Target).gameObject,
                                (object)f
                                ));
 }
Exemplo n.º 2
0
 public static void RegisterEvent(GameEventTypes eventType, GameEventCallback callback)
 {
     lock (eventLock)
     {
         List <GameEventCallback> callbackList = eventMap[eventType];
         callbackList.Add(callback);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Removes a delegate from an IGameEvent list, if it exists.
        /// Example:
        /// GlobalEventHandler.Unregister<PlayerDeathEvent>(OnPlayerDeathEvent)
        /// ...
        /// public void OnPlayerDeathEvent(PlayerDeathEvent evt){}
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="f"></param>
        public static void Unregister <T>(GameEventCallback <T> f) where T : IGameEvent
        {
            // Grab the Type and make a temporary Tuple containing all the necessary data
            Type type = typeof(T);

            // Don't bother looking if it doesn't exist
            if (_eventList.ContainsKey(type))
            {
                _eventList[type].RemoveAll(x => (GameEventCallback <T>)x.DelegatePtr == f);
            }
        }
    public static void RemoveListener(GameEvent _event, Action method)
    {
        GameEventCallback callback = new GameEventCallback {
            Action = method
        };

        if (eventDic.ContainsKey(_event))
        {
            if (eventDic[_event].Contains(callback))
            {
                eventDic[_event].Remove(callback);
            }
        }
    }
Exemplo n.º 5
0
    public static void UnregisterEvent(GameEventTypes eventType, GameEventCallback callback)
    {
        lock (eventLock)
        {
            List <GameEventCallback> callbackList = eventMap[eventType];

            for (int i = callbackList.Count - 1; i >= 0; i--)
            {
                if (callbackList[i] == callback)
                {
                    callbackList.RemoveAt(i);
                    break;
                }
            }
        }
    }
Exemplo n.º 6
0
        /// <summary>
        /// Attaches a delegate to a specific IGameEvent.
        /// Example:
        /// GlobalEventHandler.Register<PlayerDeathEvent>(OnPlayerDeathEvent)
        /// ...
        /// public void OnPlayerDeathEvent(PlayerDeathEvent evt){}
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="f"></param>
        public static void Register <T>(GameEventCallback <T> f) where T : IGameEvent
        {
            // First, get the class Type
            Type type = typeof(T);

            // If it doesn't exist, add an entry for it
            if (!_eventList.ContainsKey(type))
            {
                _eventList.Add(type, new List <GOCallbackPair>());
            }

            // Add the delegate to the list. The Target is cast explicitly to MonoBehaviour in order to retrieve the GameObject instance
            _eventList[type].Add(new GOCallbackPair(
                                     ((MonoBehaviour)f.Target).gameObject,
                                     (object)f
                                     ));
        }
Exemplo n.º 7
0
 /// <summary>
 /// Removes a delegate from the BroadcastListeners, if it exists.
 /// </summary>
 public static void UnregisterAll(GameEventCallback <IGameEvent> f)
 {
     _allEventListeners.RemoveAll(x => (GameEventCallback <IGameEvent>)x.DelegatePtr == f);
 }