public static void ReceiveData(CmdEnum cmd, byte[] data) { if (cmd == CmdEnum.ResLogin) { ResponseLogin login = SerializeTool.Deserialize <ResponseLogin>(data); ResponseLogin(login); } else if (cmd == CmdEnum.ResAlive) { ResponseAlive alive = SerializeTool.Deserialize <ResponseAlive>(data); ResponseAlive(alive); } else if (cmd == CmdEnum.ResRegister) { ResponseRegister response = SerializeTool.Deserialize <ResponseRegister>(data); ResponseRegister(response); } else if (cmd == CmdEnum.ResCreateRoom) { ResponseCreateRoom response = SerializeTool.Deserialize <ResponseCreateRoom>(data); ResponseCreateRoom(response); } else if (cmd == CmdEnum.ResGetRooms) { ResponseGetRooms response = SerializeTool.Deserialize <ResponseGetRooms>(data); ResponseGetRooms(response); } else if (cmd == CmdEnum.ResDeleteRoom) { ResponseDeleteRoom response = SerializeTool.Deserialize <ResponseDeleteRoom>(data); ResponseDeleteRoom(response); } }
// Update is called once per frame private void Update() { if (Input.GetKeyDown(KeyCode.R)) { People getFromFile = SerializeTool.Deserialize <People>(System.Text.Encoding.UTF8.GetString(IO.Read("Test_SerializeTool_Data.txt"))); Debug.Log("姓名:" + getFromFile.Name); Debug.Log("年龄:" + getFromFile.Age); Debug.Log("性别:" + getFromFile.Gender.ToString()); Debug.Log("描述:" + getFromFile.Describe); } }
/// <summary> /// 加载数据 /// </summary> public void LoadReplayData() { operationInfo.Clear(); string data = System.Text.Encoding.UTF8.GetString(IO.Read("ReplayData.txt")); JObject jobect = JObject.Parse(data); operationInfo = SerializeTool.Deserialize <List <OperationInfo> >(jobect["ReplayInfo"].ToString()); foreach (var item in operationInfo) { item.replayEntity = (IRePlayEvent)UnityObjectManager.GetComponentByID(item.comID); } Debug.Log("Load Success"); }
private void method_0() { while (!this.bool_2) { if (this.bool_3) { break; } if ((this.udpClient_0 != null) && ((this.udpClient_0.Available > 5) || this.udpClient_0.Client.Connected)) { byte[] buffer; try { buffer = this.udpClient_0.Receive(ref this.ipendPoint_0); } catch (Exception exception) { this.ilog_0.ErrorFormat("接收数据异常:{0}", exception.ToString()); Thread.Sleep(500); continue; } object obj2 = SerializeTool.Deserialize(buffer); Type type = obj2.GetType(); if (type == typeof(LoginOKMessage)) { LoginOKMessage message = (LoginOKMessage)obj2; this.bool_1 = true; if (message.Code.Equals("0000")) { this.bool_0 = true; } this.ipendPoint_1 = message.EndPoint; this.method_2(message); } else if (type == typeof(HtmlMessage)) { HtmlMessage message2 = (HtmlMessage)obj2; ReceiveOKMessage message3 = new ReceiveOKMessage(this.string_0, this.string_1, message2.Id); buffer = SerializeTool.Serialize(message3); this.udpClient_0.Send(buffer, buffer.Length, this.ipendPoint_0); this.method_1(message2); } else if (type == typeof(StopSrvMessage)) { this.bool_3 = true; StopSrvMessage message4 = (StopSrvMessage)obj2; this.method_3(message4); } else { this.ilog_0.ErrorFormat("接收到的消息格式错误:{0}", type.ToString()); } } else if (!this.bool_0 && (DateTime.Now.Subtract(this.dateTime_0).TotalSeconds > this.MaxConnWaitTime)) { this.dateTime_0 = DateTime.Now.AddYears(1); LoginOKMessage message5 = new LoginOKMessage("Z999", new IPEndPoint(IPAddress.Any, 0)) { Mess = string.Concat(new object[] { "登录超时[", this.ipendPoint_0.Address, ":", this.ipendPoint_0.Port, "]" }) }; this.method_2(message5); } Thread.Sleep(500); } bool flag = this.bool_3; this.bool_3 = false; this.bool_2 = false; if (flag && (this.ReConnectEvent != null)) { this.ReConnectEvent(); } }