コード例 #1
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
 public EventInfo(string type, EventListenerDele _listener, int _priority = 0, bool _dispatchOnce = false)
 {
     this.priority     = _priority;
     this.dispatchOnce = _dispatchOnce;
     this.eventType    = type;
     this.listener     = _listener;
 }
コード例 #2
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
    /// <summary>
    ///  执行一次针对eventKey的监听器挂接
    /// </summary>
    /// <param name="type">事件类型</param>
    /// <param name="_listener">回调函数</param>
    /// <param name="_priority">优先级</param>
    /// <param name="_dispatchOnce">是否只派发一次</param>
    private void AttachListenerNow(string type, EventListenerDele _listener, int _priority = 0, bool _dispatchOnce = false)
    {
        if (null == _listener || string.IsNullOrEmpty(type))
        {
            return;
        }
        if (!mEventDic.ContainsKey(type))
        {
            mEventDic.Add(type, new List <EventInfo>());
        }

        if (this.HasListener(type, _listener))
        {
            Debug.Log("LogicNode, AttachListenerNow: " + _listener + " is already in list for event: " + type.ToString());
            return;
        }

        List <EventInfo> listenerList = mEventDic[type];

        EventInfo ev = new EventInfo(type, _listener, _priority, _dispatchOnce);

        int pos = 0;
        int countListenerList = listenerList.Count;

        for (int n = 0; n < countListenerList; n++)
        {
            if (ev.priority > listenerList[n].priority)
            {
                break;
            }
            pos++;
        }
        listenerList.Insert(pos, ev);
    }
コード例 #3
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
    /// <summary>
    /// 执行一次针对eventKey的监听器摘除
    /// </summary>
    /// <param name="type">事件类型</param>
    /// <param name="_listener">监听函数</param>
    /// <param name="_priority">优先级</param>
    /// <param name="_dispatchOnce">是否只执行一次</param>
    private void DetachListenerNow(string type, EventListenerDele _listener)
    {
        //listener == null is valid due to unexpected GameObject.Destroy
        if (string.IsNullOrEmpty(type) || _listener == null)
        {
            Debug.LogError("回调函数或者 事件类型不能为空");
            return;
        }
        if (!mEventDic.ContainsKey(type))
        {
            return;
        }

        List <EventInfo> listenerList = mEventDic[type];
        EventInfo        ev           = null;

        foreach (EventInfo ei in listenerList)
        {
            if (ei.listener == _listener)
            {
                ev = ei;
            }
        }
        if (ev != null)
        {
            listenerList.Remove(ev);
        }
    }
コード例 #4
0
ファイル: EventNode.cs プロジェクト: paradisewu/U3DYKFamework
 public void Clean()
 {
     this.listener     = null;
     this.dispatchOnce = false;
     this.eventType    = string.Empty;
     this.priority     = 0;
 }
コード例 #5
0
ファイル: EventNode.cs プロジェクト: sheenli/Event-unity
 public void Clean()
 {
     listener     = null;
     dispatchOnce = false;
     eventType    = string.Empty;
     priority     = 0;
 }
コード例 #6
0
ファイル: EventNode.cs プロジェクト: sheenli/Event-unity
 public void Set(string type, EventListenerDele _listener, int _priority = 0, bool _dispatchOnce = false)
 {
     priority     = _priority;
     dispatchOnce = _dispatchOnce;
     eventType    = type;
     listener     = _listener;
 }
コード例 #7
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
 /// <summary>
 /// 是否存在这个监听函数
 /// </summary>
 /// <param name="type">事件类型</param>
 /// <param name="_listener">回调函数</param>
 /// <returns></returns>
 public bool HasListener(string type, EventListenerDele _listener)
 {
     if (this.mEventDic.ContainsKey(type))
     {
         foreach (EventInfo listener in this.mEventDic[type])
         {
             if (listener.listener == _listener)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #8
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
 /// <summary>
 /// 摘除一个监听eventKey消息的消息监听器
 /// 监听器将于下一逻辑帧执行前摘除
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="eventKey"></param>
 public void DetachListener(string type, EventListenerDele _listener)
 {
     if (threadSafe)
     {
         lock (m_listenersToUpdate)
         {
             m_listenersToUpdate.Enqueue(new ListenerPack(new EventInfo(type, _listener), type, false));
         }
     }
     else
     {
         m_listenersToUpdate.Enqueue(new ListenerPack(new EventInfo(type, _listener), type, false));
     }
 }
コード例 #9
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
 /// <summary>
 /// 挂接一个监听eventKey消息的消息监听器
 /// 监听器将于下一逻辑帧执行前挂接
 /// </summary>
 /// <param name="type">消息id</param>
 /// <param name="_listener">回调函数</param>
 /// <param name="_priority">优先级</param>
 /// <param name="_dispatchOnce">是否只接受一次</param>
 public void AttachListener(string type, EventListenerDele _listener, int _priority = 0, bool _dispatchOnce = false)
 {
     if (threadSafe)
     {
         lock (m_listenersToUpdate)
         {
             m_listenersToUpdate.Enqueue(new ListenerPack(new EventInfo(type, _listener, _priority, _dispatchOnce), type, true));
         }
     }
     else
     {
         m_listenersToUpdate.Enqueue(new ListenerPack(new EventInfo(type, _listener, _priority, _dispatchOnce), type, true));
     }
 }
コード例 #10
0
ファイル: EventNode.cs プロジェクト: paradisewu/U3DYKFamework
        public static EventInfo Get(string type, EventListenerDele _listener, int _priority = 0, bool _dispatchOnce = false)
        {
            EventInfo info = null;

            if (mPools.Count > 0)
            {
                info = mPools.Dequeue();
                info.Set(type, _listener, _priority, _dispatchOnce);
            }
            else
            {
                info = new EventInfo(type, _listener, _priority, _dispatchOnce);
            }
            return(info);
        }
コード例 #11
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
 /// <summary>
 ///  执行一次针对eventKey的监听器挂接
 /// </summary>
 /// <param name="type">事件类型</param>
 /// <param name="_listener">回调函数</param>
 /// <param name="_priority">优先级</param>
 /// <param name="_dispatchOnce">是否只派发一次</param>
 private void AttachListenerNow(int type, EventListenerDele _listener, int _priority = 0, bool _dispatchOnce = false)
 {
     AttachListenerNow(type.ToString(), _listener, _priority, _dispatchOnce);
 }
コード例 #12
0
ファイル: EventNode.cs プロジェクト: sunl4nl/YKFrameworkXLUA
 public void DetachListener(int type, EventListenerDele _listener)
 {
     DetachListener(type.ToString(), _listener);
 }
コード例 #13
0
ファイル: EventNode.cs プロジェクト: paradisewu/U3DYKFamework
 private EventInfo(string type, EventListenerDele _listener, int _priority = 0, bool _dispatchOnce = false)
 {
     Set(type, _listener, _priority, _dispatchOnce);
 }