private void _PlayerTankUpdateRequest(Player player, byte[] data) { PlayerTankRequest result = new PlayerTankRequest(); PlayerTankRequest receive = NetworkUtils.Deserialize <PlayerTankRequest>(data); if (Server.Rooms.ContainsKey(receive.RoomId)) { Room room = Server.Rooms[receive.RoomId]; foreach (Player _player in room.Players) { if (_player.GUID != receive.GUID) { result = receive; result.Suc = true; data = NetworkUtils.Serialize(result); _player.Send(MessageType.PlayerTankUpdateRequest, data); } } } else { // room not exist result.Suc = false; data = NetworkUtils.Serialize(result); player.Send(MessageType.PlayerTankUpdateRequest, data); } }
// 更新远程玩家 public static void UpdateRemotePlayerStatus(PlayerTankRequest ptr) { foreach (RemotePlayer rp in remotePlayerList) { if (rp.GUID == ptr.GUID) { rp.MAX_HEALTH = ptr.MaxHealth; rp.hp = ptr.Hp; rp.transform.position = new Vector3(ptr.Vec3_x, ptr.Vec3_y, ptr.Vec3_z); //Vector3 des = new Vector3(ptr.Vec3_x-rp.transform.position.x, // ptr.Vec3_y-rp.transform.position.y, // ptr.Vec3_z-rp.transform.position.z); //rp.transform.Translate(des/3f, Space.World); rp.transform.rotation = new Quaternion(ptr.Rot4_a, ptr.Rot4_b, ptr.Rot4_c, ptr.Rot4_d); if (ptr.AttackNormal == true) { GameObject.Instantiate(RemotePlayer.bullet, rp.FirePosition.transform.position, rp.FirePosition.transform.rotation); } break; } else if (rp.GUID == 0) { rp.GUID = ptr.GUID; rp.nickName = ptr.NickName; rp.gameObject.SetActive(true); break; } //if (!rp.gameObject.activeInHierarchy) ; } }
private static void _PlayerTankUpdateRequest(byte[] data) { PlayerTankRequest result = NetworkUtils.Deserialize <PlayerTankRequest>(data); if (result.Suc) { Debug.Log("收到来自服务器发送的tank位置更新包"); LocalPlayerController.UpdateRemotePlayerStatus(result); } }
public static void UploadTankStatus(PlayerTankRequest ptr) { byte[] data = NetworkUtils.Serialize(ptr); Enqueue(MessageType.PlayerTankUpdateRequest, data); }