/// <summary> /// 注册消息 /// </summary> /// <param name="id"></param> /// <param name="handle"></param> public void RegistMsg(MsgID id, IMsgHandle handle) { List <IMsgHandle> handlist; if (msgDict.ContainsKey(id)) { msgDict.TryGetValue(id, out handlist); if (handlist == null) { handlist = new List <IMsgHandle>(); } handlist.Add(handle); } else { handlist = new List <IMsgHandle>(); handlist.Add(handle); msgDict.Add(id, handlist); } }
/// <summary> /// 移除消息 /// </summary> /// <param name="id"></param> /// <param name="handle"></param> /// <returns></returns> public bool RemoveMsg(MsgID id, IMsgHandle handle) { bool result = false; if (msgDict.ContainsKey(id)) { List <IMsgHandle> handlelist; msgDict.TryGetValue(id, out handlelist); if (handlelist != null && handlelist.Count >= 0) { for (int i = 0; i < handlelist.Count; i++) { if (handlelist[i] == handle) { handlelist.RemoveAt(i); return(true); } } } } return(result); }