/// /// 只有当消息的接受者不存在的时候,才会去考虑创建消息的接受者 /// 创建Controller /// void createController(int senderID, LogicalType receiver, MsgParam param) { string name = receiver.ToString(); GameObject go = new GameObject(name); go.AddComponent(binder.getController(name)); UnityUtils.AddChild(go, ControllerMain.CtrlMain.gameObject); ControllerEx ctrlEx = go.GetComponent <ControllerEx>(); ctrlEx.CtrlType = receiver; AsyncTask.QueueOnMainThread(() => { param.Sender = senderID; param.Receiver = go.GetInstanceID(); ctrlEx.UI_OnReceive(param); }, 1f); }
public bool SendMessage(int senderID, int recID, MsgParam param) { param.Sender = senderID; param.Receiver = recID; bool sent = false; if (param == null) { ConsoleEx.DebugLog("We can't send empty message to other.", ConsoleEx.RED); return(sent); } if (uiCollection.ContainsKey(recID)) { ConsoleEx.DebugLog("We can't send message to UI layer.", ConsoleEx.RED); return(sent); } ControllerEx CtrlEx = null; if (ctlCollection.TryGetValue(recID, out CtrlEx)) { if (CtrlEx != null) { sent = true; CtrlEx.UI_OnReceive(param); } else { sent = false; } } else { sent = false; ConsoleEx.DebugLog("Controller doesn't instanciate yet.", ConsoleEx.YELLOW); } return(sent); }