public void SendingPosition(Vector3 pos, Vector3 rot) { PlayerInputMsg m = new PlayerInputMsg(); m.position = pos; m.rotation = rot; SendToServer(JsonUtility.ToJson(m)); }
void OnData(DataStreamReader stream) { NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp); stream.ReadBytes(bytes); string recMsg = Encoding.ASCII.GetString(bytes.ToArray()); NetworkHeader header = JsonUtility.FromJson <NetworkHeader>(recMsg); switch (header.cmd) { case Commands.HANDSHAKE: HandshakeMsg hsMsg = JsonUtility.FromJson <HandshakeMsg>(recMsg); Debug.Log("Handshake message received!"); break; case Commands.PLAYER_UPDATE: PlayerUpdateMsg puMsg = JsonUtility.FromJson <PlayerUpdateMsg>(recMsg); Debug.Log("Player update message received!"); break; case Commands.SERVER_UPDATE: ServerUpdateMsg suMsg = JsonUtility.FromJson <ServerUpdateMsg>(recMsg); Debug.Log("Server update message received!"); break; //*** case Commands.NEW_PLAYER: NewPlayer neMsg = JsonUtility.FromJson <NewPlayer>(recMsg); Debug.Log("New Player Joining!"); if (P_ID != neMsg.ID) { Instantiate(Player, new Vector3(5.0f, 0.0f, 0.0f), Quaternion.identity); } break; case Commands.PLAYER_INPUT: PlayerInputMsg move = JsonUtility.FromJson <PlayerInputMsg>(recMsg); Debug.Log("Player moving!"); foreach (GameObject cp in GameObject.FindGameObjectsWithTag("Player")) { if (cp != self) { cp.transform.position = move.move; } } break; default: Debug.Log("Unrecognized message received!"); break; } }
void OnData(DataStreamReader stream, int i) { NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp); stream.ReadBytes(bytes); string recMsg = Encoding.ASCII.GetString(bytes.ToArray()); NetworkHeader header = JsonUtility.FromJson <NetworkHeader>(recMsg); switch (header.cmd) { case Commands.HANDSHAKE: HandshakeMsg hsMsg = JsonUtility.FromJson <HandshakeMsg>(recMsg); Debug.Log("Handshake message received!"); break; case Commands.PLAYER_UPDATE: PlayerUpdateMsg puMsg = JsonUtility.FromJson <PlayerUpdateMsg>(recMsg); Debug.Log("Player update message received!"); break; case Commands.SERVER_UPDATE: ServerUpdateMsg suMsg = JsonUtility.FromJson <ServerUpdateMsg>(recMsg); Debug.Log("Server update message received!"); break; //*** case Commands.NEW_PLAYER: NewPlayer neMsg = JsonUtility.FromJson <NewPlayer>(recMsg); Debug.Log("New Player Joining!"); N_Player.Add(neMsg); foreach (NetworkConnection cp in m_Connections) { SendToClient(JsonUtility.ToJson(neMsg), cp); } break; case Commands.PLAYER_INPUT: PlayerInputMsg move = JsonUtility.FromJson <PlayerInputMsg>(recMsg); Debug.Log("Player moving!"); foreach (NetworkConnection cp in m_Connections) { SendToClient(JsonUtility.ToJson(move), cp); } break; default: Debug.Log("SERVER ERROR: Unrecognized message received!"); break; } }
//player moving public void PlayerMove(GameObject s) { PlayerInputMsg PM = new PlayerInputMsg(); /* * Vector2 movementVector = new Vector2(Input.GetAxis("Horizontal"), * Input.GetAxis("Vertical")); * movementVector *= speed; * PM.move = s.transform.position= movementVector;*/ PM.move = s.transform.position; PM.ID = P_ID; SendToServer(JsonUtility.ToJson(PM)); }
void OnData(DataStreamReader stream, int i) { NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp); stream.ReadBytes(bytes); string recMsg = Encoding.ASCII.GetString(bytes.ToArray()); NetworkHeader header = JsonUtility.FromJson <NetworkHeader>(recMsg); int index = MatchPlayerWithId(m_Connections[i].InternalId.ToString()); switch (header.cmd) { case Commands.PLAYER_INPUT: PlayerInputMsg input = JsonUtility.FromJson <PlayerInputMsg>(recMsg); plMsg.players[index].cubePos = input.position; plMsg.players[index].cubeRot = input.rotation; msgInterval[index] = Time.deltaTime; break; default: Debug.Log("SERVER ERROR: Unrecognized message received!"); break; } }
private void SyncPlayerInput(int playerID, PlayerInputMsg msg) { Debug.Log(System.String.Format("Player {0} sync input", playerID)); }