//处理协议数据协程 xlua //这里仅仅是提取了数据到运作层。至于反序列化,以及收到消息的回调,都在在运作层处理。 IEnumerator DealMsgCorLua() { while (true) { lock (m_MsgQueue) { while (m_MsgQueue.Count > 0) { NetMsgPacket tempMsgPacket = m_MsgQueue.Dequeue(); int tempMsgId = tempMsgPacket.msgId; if (tempMsgId <= 0) { ZLogger.Warning("网络数据不正常,不处理此协议,协议ID:{0}", tempMsgId); } else { try { byte[] tempData = tempMsgPacket.data; NetCallMethod("OnMessage", tempMsgId, tempData); if (tempMsgId == 1201) { m_lostHeartTime = 0; //暂定心跳协议ID为1201,重置心跳网络检测 } } catch (Exception e) { OnDisconnect(NetResultType.Exception, "消息报错: 协议Id:" + tempMsgId + " >> " + e.Message + "|" + e.StackTrace); } } } } yield return(null); } }
private static CycleObject GetFreeObject() { lock (LockObj) { var count = Objects.Count; for (var i = 0; i < count; i++) { var co = Objects[i]; if (!co.Use) { return(co); } } //create new if (Count >= InitCount) { ZLogger.Warning("over init capacity, auto increasing count"); } var cObject = new CycleObject { Obj = new ZObject(), Use = true, }; Objects.Add(cObject); Count++; return(cObject); } }
/// <summary> /// 协议注册 /// </summary> public void RegistProtocal(MessageID canMsgType, NetEvenetCallBack canCallBack) { if (m_MsgDelegateDic.ContainsKey((int)canMsgType)) { ZLogger.Warning("多次订阅同一个协议:{0}", canMsgType); } else { m_MsgDelegateDic.Add((int)canMsgType, canCallBack); } }
public static void Delete(ZObject obj) { var co = GetCycleObjectByObj(obj); if (co == null) { ZLogger.Warning($"{obj.GetType().Name} is not a cycle object"); return; } co.Use = false; }
public void RegistProtocal(MessageID canMsgType, NetEvenetCallBack canCallBack) { if (m_ProtocList.Contains(canMsgType)) { ZLogger.Warning("协议事件重复注册"); return; } else { m_ProtocList.Add(canMsgType); } NetWorkMgr.Instance.RegistProtocal(canMsgType, canCallBack); }
// 打开界面回调 void _OnViewLoadComplete(string path, object go, object param1 = null, object param2 = null, object param3 = null) { GameObject prefabObj = go as GameObject; if (prefabObj == null) { ZLogger.Warning("{0} 加载成功,但是 result.asset = null ,请检查资源!!!!!", ViewName()); } BindGo(prefabObj); selfState = ViewState.Loaded; Init(); selfState = ViewState.Ininting; updateViewState(this, UIMgr.ViewStateType.LOAD_COMPLETE); RegisterUpdateHandlerHold(); _OpenViewInit(); }