コード例 #1
0
 // params 可变数组 参数
 // 去掉一个脚本的若干的消息
 public void UnRegisterMsg(CMonoBehaviour monoBase, params ushort[] msgs)
 {
     for (int i = 0; i < msgs.Length; i++)
     {
         UnRegistMsg(msgs[i], monoBase);
     }
 }
コード例 #2
0
        // mono:要注册的脚本
        // msgs:每个消息可以注册多个脚本
        public void RegisterMsg(CMonoBehaviour behaviour, ushort[] msgs)
        {
            for (int i = 0; i < msgs.Length; i++)
            {
                CMsgNode msgNode = new CMsgNode(behaviour);

                RegisterMsg(msgs[i], msgNode);
            }
        }
コード例 #3
0
        // 释放 中间,尾部。
        public void UnRegistMsg(ushort msgId, CMonoBehaviour behaviour)
        {
            if (!msgDic.ContainsKey(msgId))
            {
                Debug.LogWarning("not contain id ==" + msgId);
                return;
            }
            else
            {
                CMsgNode msgNode = msgDic[msgId];
                if (msgNode.behaviour == behaviour)                 // 去掉头部 包含两种情况
                {
                    CMsgNode header = msgNode;

                    // 已经存在这个消息
                    // 头部
                    if (header.next != null)
                    {
                        msgDic [msgId] = msgNode.next;                         // 直接指向下一个
                        header.next    = null;

                        header.behaviour = msgNode.next.behaviour;
                        header.next      = msgNode.next.next;
                    }
                    else                     // 后面没有节点的情况
                    {
                        header.next = null;
                        msgDic.Remove(msgId);
                    }
                }
                else                                                                    // 去掉尾部 和中间的节点
                {
                    while (msgNode.next != null && msgNode.next.behaviour != behaviour) // 下一个不是我要找的 node 就一直遍历
                    {
                        msgNode = msgNode.next;
                    }                     // 表示已经找到了 该节点

                    // 没有引用 会自动释放
                    if (msgNode.next.next != null)                     // 去掉中间的
                    {
                        CMsgNode curNode = msgNode.next;               // 保存一下

                        msgNode.next = curNode.next;
                        //					tmp.next = tmp.next.next;
                        curNode.next = null; // 把相关联的指针释放
                    }
                    else                     // 去掉尾部的
                    {
                        // tmp表示要找的节点的上一个节点
                        msgNode.next = null;
                    }
                }
            }
        }
コード例 #4
0
 public CMsgNode(CMonoBehaviour behaviour)
 {
     this.behaviour = behaviour;
     this.next      = null;
 }
コード例 #5
0
 /// <summary>
 /// Uns the register self.
 /// </summary>
 /// <param name="mono">Mono.</param>
 /// <param name="msg">Message.</param>
 public void UnRegisterSelf(CMonoBehaviour mono, ushort[] msg)
 {
     mCurMgr.UnRegisterMsg(mono, msg);
 }
コード例 #6
0
 /// <summary>
 /// Registers the self.
 /// </summary>
 /// <param name="mono">Mono.</param>
 public void RegisterSelf(CMonoBehaviour mono)
 {
     mCurMgr.RegisterMsg(mono, msgIds);
 }