Exemple #1
0
        /// <summary>
        /// 注册消息封装
        /// </summary>
        public void RegisterMsg(string _msgName, Action <object> _handle)
        {
            EventsUtil.RegisterMsg(_msgName, _handle);
            MsgRecord _record = MsgRecord.Allocate(_msgName, _handle);

            mMsgRecorder.Add(_record);
        }
Exemple #2
0
 /// <summary>
 /// 更改OnDestroy方法处理事件的自动注销
 /// </summary>
 private void OnDestroy()
 {
     OnBeforeDestroy();
     if (mMsgRecorder.Count > 0)
     {
         for (int i = mMsgRecorder.Count - 1; i >= 0; i--)
         {
             EventsUtil.UnRegisterMsg(mMsgRecorder[i].msgName, mMsgRecorder[i].handle);
             mMsgRecorder[i].Recycle();
         }
         mMsgRecorder.Clear();
     }
 }
Exemple #3
0
        private static void MenuClicked_03()
        {
            string _msg = "问好";

            System.Action <object> _act_01 = (_data) => { Debug.Log("收到1信息:" + _data); };
            System.Action <object> _act_02 = (_data) => { Debug.Log("收到2信息:" + _data); };
            EventsUtil.RegisterMsg(_msg, _act_01);
            EventsUtil.RegisterMsg(_msg, _act_02);
            EventsUtil.SendMsg(_msg, "1111");
            EventsUtil.UnRegisterMsg(_msg, _act_01);
            EventsUtil.SendMsg(_msg, "2222");
            EventsUtil.UnRegisterMsgAll(_msg);
        }
Exemple #4
0
        /// <summary>
        /// 注销消息
        /// </summary>
        public void UnRegisterMsg(string _msgName, Action <object> _handle)
        {
            List <MsgRecord> _records = mMsgRecorder.FindAll(_record =>
            {
                return(_record.msgName == _msgName && _record.handle == _handle);
            });

            if (_records.Count > 0)
            {
                for (int i = 0; i < _records.Count; i++)
                {
                    EventsUtil.UnRegisterMsg(_records[i].msgName, _records[i].handle);
                    _records[i].Recycle();
                    mMsgRecorder.Remove(_records[i]);
                }
            }
        }
Exemple #5
0
 /// <summary>
 /// 信息的发送
 /// </summary>
 public void SendMsg(string _msgName, object _obj)
 {
     EventsUtil.SendMsg(_msgName, _obj);
 }