/// <summary> /// 注销所有消息 /// </summary> public void UnRegiserAllMsg() { foreach (MsgRecord mMsgRecord in mMsgRecords) { MsgCenter.UnRegister(mMsgRecord.MsgType, mMsgRecord.OnMsgReceived); mMsgRecord.Recycle(); } }
/// <summary> /// 注销指定消息 /// </summary> /// <param UIName="msgType"></param> public void UnRegisterMsg(Enum msgType) { var selectedRecords = mMsgRecords.FindAll((record) => Equals(record.MsgType, msgType)); selectedRecords.ForEach(record => { MsgCenter.UnRegister(record.MsgType, record.OnMsgReceived); mMsgRecords.Remove(record); record.Recycle(); }); selectedRecords.Clear(); }
/// <summary> /// 发送消息 /// </summary> /// <param UIName="msgType"></param> /// <param UIName="data"></param> public void SendMsg(Enum msgType, object data = null) { MsgCenter.SendMsg(msgType, data); }
/// <summary> /// 消息注册 /// </summary> /// <param UIName="msgType"></param> /// <param UIName="msgListener"></param> public void RegisterMsg(Enum msgType, Action <object> msgListener) { MsgCenter.RegisterMsg(msgType, msgListener); mMsgRecords.Add(MsgRecord.Allocate(msgType, msgListener)); }