示例#1
0
        //移除一个指定type,code的消息回调函数
        public static void RemoveMsgListener(MoudleType type, uint code, MsgCallback callback)
        {
            Dictionary <uint, MsgCallback> subDic = null;

            if (!_dic.TryGetValue(type, out subDic))
            {
                Debug.LogWarning("移除监听失败:" + type.ToString() + " MoudleType 的委托字典不存在");
                return;
            }

            if (!subDic.ContainsKey(code))
            {
                Debug.LogWarning("移除监听失败:" + type.ToString() + " MoudleType ," + code.ToString() + " code 的委托不存在");
                return;
            }

            subDic[code] -= callback;

            if (subDic[code] == null)
            {
                subDic.Remove(code);
            }

            if (subDic.Keys.Count == 0)
            {
                _dic.Remove(type);
            }
        }
示例#2
0
        //移除一个指定type,多个code的消息回调函数
        public static void RemoveMsgListener(MoudleType type, uint[] codes, MsgCallback callback)
        {
            Dictionary <uint, MsgCallback> subDic = null;

            if (!_dic.TryGetValue(type, out subDic))
            {
                Debug.LogWarning("移除监听失败:" + type.ToString() + " MoudleType 的委托字典不存在");
                return;
            }

            for (int i = 0; i < codes.Length; i++)
            {
                if (!subDic.ContainsKey(codes[i]))
                {
                    Debug.LogWarning("移除监听失败:" + type.ToString() + " MoudleType ," + codes[i].ToString() + " code 的委托不存在");
                    continue;
                }

                subDic[codes[i]] -= callback;

                if (subDic[codes[i]] == null)
                {
                    subDic.Remove(codes[i]);
                }
            }

            if (subDic.Keys.Count == 0)
            {
                _dic.Remove(type);
            }
        }
示例#3
0
        //清空指定type的所有消息回调函数
        public static void ClearMsgListener(MoudleType type)
        {
            Dictionary <uint, MsgCallback> subDic = null;

            if (!_dic.TryGetValue(type, out subDic))
            {
                Debug.LogWarning("清空监听失败:" + type.ToString() + " MoudleType 的委托字典不存在");
                return;
            }
            subDic.Clear();
            _dic.Remove(type);
        }