private static void MenuClicked() { //全部清空,确保事例有效 MsgDispatcher.UnRegisterAll("MSG1"); MsgDispatcher.Register("MSG1", OnMsgReceived); MsgDispatcher.Register("MSG1", OnMsgReceived); MsgDispatcher.Send("MSG1", "hello world"); MsgDispatcher.UnRegister("MSG1", OnMsgReceived); MsgDispatcher.Send("MSG1", "hello"); }
private void Awake() { MsgDispatcher.UnRegisterAll("Do"); MsgDispatcher.UnRegisterAll("OK"); RegisterMsg("Do", DoSomething); RegisterMsg("Do", DoSomething); RegisterMsg("Do1", _ => { }); RegisterMsg("Do2", _ => { }); RegisterMsg("Do3", _ => { }); RegisterMsg("OK", data => { Debug.Log(data); UnRegisterMsg("OK"); }); }