//先检查消息id的回调是否存在. //如果不存在则调用action private void OnRead(IChannelPipeline pipe, IResponseMessage message) { var channelName = pipe.Channel.Options.Name; var msg = message as ResponseMessagePacket; if (this.ReadCallBack != null) { //当前不是主线程,,得添加到loom中 Loom.QueueOnMainThread(() => { ReadCallBack.Invoke(pipe, msg); }); } GameAction action; if (this.SendActions.ContainsKey(msg.MessageID)) { action = this.SendActions[msg.MessageID]; this.SendActions.Remove(msg.MessageID); } else { action = ActionFactory.CreateAction.Invoke(channelName, msg.ContractID); } if (action != null) { if (msg.StateCode == 200) { action.Handler(msg.BodyContent); return; } action.HandlerError(new ErrorInfo() { StateCode = msg.StateCode, MsgId = msg.MessageID }); } }
void Awake() { _current = this; initialized = true; }
public NetService() { //在主线程初始化loom this.loom = Loom.Current; }