public void Add(IEventListener <TEventListener> listener, GameObject owner, ReceiveEventStates receiveEventState)
            {
                EventListenerInfo info = new EventListenerInfo
                {
                    Listener          = listener,
                    Owner             = owner,
                    ReceiveEventState = receiveEventState,
                };

                if (receiveEventState == ReceiveEventStates.Always)
                {
                    _alwaysReceiveEvents.Add(info);
                }
                else
                {
                    List <EventListenerInfo> listeners;
                    if (!_gameObjToListenersMap.TryGetValue(owner, out listeners))
                    {
                        listeners = new List <EventListenerInfo>();
                        _gameObjToListenersMap[owner] = listeners;
                    }

                    listeners.Add(info);
                }
            }
Ejemplo n.º 2
0
    public void AddKeyBoardEventListener(DlgtKeyBoardEventListener newlistener, float responseInterval)
    {
        //是否已经存在这个键的监听
        EventListenerInfo listenerinfo = new EventListenerInfo();

        listenerinfo.listener = newlistener;
        listenerinfo.eventResponseInterval = responseInterval;
        listKeyBoardEvents.Add(listenerinfo);
    }
Ejemplo n.º 3
0
 public void RemoveKeyBoardEventListener(DlgtKeyBoardEventListener listener)
 {
     //从监听字典中移除
     for (int i = listKeyBoardEvents.Count - 1; i >= 0; i--)
     {
         EventListenerInfo listenerInfo = listKeyBoardEvents[i];
         if (listenerInfo != null && listenerInfo.listener != null && listenerInfo.listener == listener)
         {
             listenerInfo.listener -= listener;
             listKeyBoardEvents.RemoveAt(i);
         }
     }
 }
Ejemplo n.º 4
0
 public void removeListener(EventListener func, String type)
 {
     //don't remove event handlers during tick events
     if (myIsTicking == true)
     {
         EventListenerInfo i = new EventListenerInfo();
         i.func      = func;
         i.eventName = type;
         myPendingRemoves.Enqueue(i);
     }
     //otherwise it is safe to remove them here
     else
     {
         myRootEventListener.removeEventListener(func, type);
     }
 }
Ejemplo n.º 5
0
 public void addListener(EventListener func, String type)
 {
     //if adding during an event dispatch, queue for later
     if (myIsTicking == true)
     {
         EventListenerInfo i = new EventListenerInfo();
         i.func      = func;
         i.eventName = type;
         myPendingAdds.Enqueue(i);
     }
     //otherwise just add the event handler here
     else
     {
         registerEvent(type);
         myRootEventListener.addEventListener(func, type);
     }
 }
            public void Remove(IEventListener <TEventListener> listener, GameObject owner)
            {
                List <EventListenerInfo> listeners;

                if (_gameObjToListenersMap.TryGetValue(owner, out listeners))
                {
                    for (int infoIndex = 0; infoIndex < listeners.Count; infoIndex++)
                    {
                        EventListenerInfo info = listeners[infoIndex];
                        if (info.Listener == listener)
                        {
                            listeners.Remove(info);
                            break;
                        }
                    }
                }
            }