Exemplo n.º 1
0
    private void FixedUpdate()
    {
        if (GameManager.Instance.IsGameStart)
        {
            if (Player.IsMine())
            {
                Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
                Vector3 moveVelocity = moveInput.normalized * moveSpeed;
                _rigidBody.MovePosition(_rigidBody.position + moveVelocity * Time.fixedDeltaTime);

                CLIENTtoSERVER_GamePlayerMovePacketData data = new CLIENTtoSERVER_GamePlayerMovePacketData();

                data.playerKey = GameFramework.Instance.MyPlayer.PlayerKey;
                data.gameKey   = GameManager.Instance.GameKey;

                data.posX = transform.position.x;
                data.posY = transform.position.y;
                data.posZ = transform.position.z;

                data.angularX = transform.eulerAngles.x;
                data.angularY = transform.eulerAngles.y;
                data.angularZ = transform.eulerAngles.z;

                if (!GameManager.Instance.IsHost)
                {
                    NetworkManager.Instance.SendCommand((int)PROTOCOL.GAME_PLAYER_MOVE, (int)EXTRA.CLIENT_TO_SERVER, data);
                }
                else
                {
                    NetworkManager.Instance.SendCommand((int)PROTOCOL.GAME_PLAYER_MOVE, (int)EXTRA.HOST_TO_SERVER, data);
                }
            }
        }
    }
Exemplo n.º 2
0
    public void RESPONSE_GAME_PLAYER_MOVE(TcpPacket packet)
    {
        if (packet.header.extra == (int)EXTRA.SUCCESS)
        {
            SERVERtoHOST_GamePlayerMovePacketData recvData = new SERVERtoHOST_GamePlayerMovePacketData();
            recvData.Deserialize(packet);

            CLIENTtoSERVER_GamePlayerMovePacketData sendData = new CLIENTtoSERVER_GamePlayerMovePacketData();
            sendData.playerKey = recvData.playerKey;
            sendData.gameKey   = GameManager.Instance.GameKey;

            sendData.posX = recvData.posX;
            sendData.posY = recvData.posY;
            sendData.posZ = recvData.posZ;

            sendData.angularX = recvData.angularX;
            sendData.angularY = recvData.angularY;
            sendData.angularZ = recvData.angularZ;

            NetworkManager.Instance.SendCommand((int)PROTOCOL.GAME_PLAYER_MOVE, (int)EXTRA.HOST_TO_SERVER, sendData);
        }
    }