public byte[] ServerDealMsg(MessageData <BaseMessageData> data, IPEndPoint ip) { switch (data.head.cmd) { case 1: switch (data.head.scmd) { case 1: MessageData_1_1 messageData = new MessageData_1_1(); foreach (EndPoint _point in Main.Self.server.clientsEnd) { Vector3 _pos = Vector3.zero; Vector3 _rot = Vector3.zero; double _aimValue = 1; if (Main.Self.playerList.ContainsKey(_point)) { Player player = Main.Self.playerList[_point]; _pos = player.trans.localPosition; _rot = player.trans.localEulerAngles; _aimValue = player.aimValue; } messageData.players.Add(new MessageData_1_1.PlayerInfo() { ip = _point, pos = _pos, rot = _rot, aimValue = _aimValue, }); } data.body = messageData; break; case 2: break; case 10: break; default: break; } break; default: break; } data.body.dealFlg = 1; data.body._ip = ip; return(data.ToBytes()); }
public void Deal_1_1(MessageData <BaseMessageData> data) { MessageData_1_1 messageData = data.body as MessageData_1_1; for (int i = 0; i < messageData.players.Count; i++) { MessageData_1_1.PlayerInfo playerInfo = messageData.players[i]; GIPEndPoint playerIp = playerInfo.ip; if (!Main.Self.playerList.ContainsKey(playerIp)) { GameObject go = GameObject.Instantiate(Resources.Load("Player") as GameObject); Player player = go.AddComponent <Player> (); Vector3 pos = playerInfo.pos; Vector3 rot = playerInfo.rot; double aimValue = playerInfo.aimValue; player.StartCallBack += () => { player.curIp = playerIp; player.SetName(playerIp.ToString()); player.SetTrans(new List <GVector3> () { pos, rot }); player.aimValue = (float)aimValue; }; Main.Self.playerList.Add(playerIp, player); if (Main.Self.curPlayer == null && data.body._ip.Equals(playerIp)) { Main.Self.curPlayer = player; player.isLocalPlayer = true; player.StartCallBack += () => { player.SetColor(); }; } } } Debug.Log("欢迎 " + data.body._ip.ToString()); }