void OnDestroy() { BeforeDestroy(); foreach (var item in mMsgRecorder) { MsgDispatcher.UnRegister(item.MsgName, item.onMsgReceive); item.Recycle(); } mMsgRecorder.Clear(); }
static void MenuClick() { MsgDispatcher.UnRegisterAll("消息1"); MsgDispatcher.Register("消息1", OnMsgReceived); MsgDispatcher.Register("消息1", OnMsgReceived); MsgDispatcher.Send("消息1", "Hello World"); MsgDispatcher.UnRegister("消息1", OnMsgReceived); MsgDispatcher.Send("消息1", "Hello "); }
public void UnRegisterMsg(string msgName, Action <object> onMsgReceive) { var selectRecords = mMsgRecorder.FindAll(record => record.MsgName == msgName && record.onMsgReceive == onMsgReceive); selectRecords.ForEach(record => { MsgDispatcher.UnRegister(record.MsgName, record.onMsgReceive); mMsgRecorder.Remove(record); record.Recycle(); }); selectRecords.Clear(); }