public IEnumerator OnLogined(string account) { //Debugger.Enable = true; Global.OpenId = account; Debug.Log(Global.OpenId); yield return(StartCoroutine(MgobeHelper.InitSDK())); if (Global.IsInRoom()) { if (MgobeHelper.RoomInfo.FrameSyncState == FrameSyncState.Start) { //找一个客户端拿数据 //拿完直接显示对应数据,开始sim MgobeHelper.SendToClient(null, RecvType.RoomOthers, "ReConnect", () => { }); } else { UIManager.UF_GetInstance().UF_ShowView("UI System", "ui_panelcreation", null); } } else { UIManager.UF_GetInstance().UF_ShowView("UI System", "ui_panellan", null); } }
private void OnClientMsg(object[] args) { string playerId = args[0] as string; string msg = args[1] as string; var msgList = ListCache <string> .Acquire(); msgList.AddRange(msg.Split('|')); var msgType = msgList[0]; switch (msgType) { case (ClientMsgType.ReConnect): StringBuilder sb = new StringBuilder(); sb.Append(ClientMsgType.ReConnectRsp); sb.Append("|"); sb.Append(GetTimeStamp()); sb.Append("|"); var sim = SimulationManager.Instance.GetSimulation(Const.CLIENT_SIMULATION_ID); var frameDatas = sim.GetBehaviour <ComponentsBackupBehaviour>().GetEntityWorldFrameData(); var frameIdx = sim.GetBehaviour <LogicFrameBehaviour>().CurrentFrameIdx; sb.Append(frameIdx); sb.Append("|"); var frameData = frameDatas[frameIdx]; sb.Append(EntityWorldFrameData.Serilize(frameData)); sb.Append("|"); var arrKF = MgobeHelper.QueueKeyFrameCollection.ToArray(); if (arrKF.Length > 0) { for (int i = 0; i < arrKF.Length; i++) { if (i > 0) { sb.Append("&"); } sb.Append(Encoding.UTF8.GetString(PtKeyFrameCollection.Write(arrKF[i]))); } } var list = new List <string>() { playerId }; MgobeHelper.SendToClient(list, RecvType.RoomSome, sb.ToString()); break; case (ClientMsgType.ReConnectRsp): var idx = msgList[1]; var timestamp = ulong.Parse(msgList[2]); var frameStr = msgList[3]; var kfStr = msgList[4]; var entData = EntityWorldFrameData.DeSerilize(frameStr); var queueKeyFrameCollection = new ConcurrentQueue <PtKeyFrameCollection>(); if (!string.IsNullOrEmpty(kfStr)) { var kfStrs = kfStr.Split('&'); for (int i = 0; i < kfStrs.Length; i++) { queueKeyFrameCollection.Enqueue(PtKeyFrameCollection.Read(Encoding.UTF8.GetBytes(kfStrs[i]))); } } MgobeHelper.QueueKeyFrameCollection = queueKeyFrameCollection; OnAddClient(); var sim2 = SimulationManager.Instance.GetSimulation(Const.CLIENT_SIMULATION_ID); sim2.GetBehaviour <LogicFrameBehaviour>().CurrentFrameIdx = int.Parse(idx); sim2.GetEntityWorld().RollBack(entData, null); OnAllReady(null); SimulationManager.Instance.Start(timestamp); break; default: break; } ListCache <string> .Release(msgList); }