Exemplo n.º 1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && !isConnected)
        {
            communicationManager.SendMessage(ConnectPlayerMessage.CreateConnectPlayerMessageToSend(playerId));
        }
        else if (Input.GetKeyDown(KeyCode.Escape) && isConnected)
        {
            communicationManager.SendMessage(new DisconnectPlayerMessage(Random.Range(0, int.MaxValue), playerId));
            Clean();
        }

        ReadMessages();

        if (simIniTime != 0)
        {
            if (!Input.GetKey(KeyCode.K))
            {
                Interpolate();
            }
        }

        if (ownPlayer != null)
        {
            communicationManager.SendMessage(new PlayerInputMessage(playerId, ownPlayer.playerInput));
        }

        Packet outPacket = communicationManager.BuildPacket();

        if (outPacket != null)
        {
            channel.Send(outPacket);
        }
    }
Exemplo n.º 2
0
    private void SendInput()
    {
        if (_ownPlayerController != null)
        {
            _communicationManager.SendMessage(new PlayerInputMessage(PlayerId, _ownPlayerController.PlayerInput));
        }
        var data = _communicationManager.BuildPacket();

        if (data != null)
        {
            _channel.Send(data);
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        Packet s;

        if ((s = channel.GetPacket()) != null)
        {
            int messages = s.buffer.GetInt();
            for (int i = 0; i < messages; i++)
            {
                Message m = readServerMessage(s.buffer);
                if (m != null)
                {
                    ProcessMessage(m);
                }
                else
                {
                    Debug.Log("m is null");
                }
            }
            Debug.Log("Recibi algo");
        }
        if (!snapshotManager.alreadyAdded)
        {
            snapshotManager.AddInterpolated();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            //send player connect message
            ConnectPlayerMessage connectPlayerMessage = ConnectPlayerMessage.CreateConnectPlayerMessageToSend(playerId);
            cm.SendMessage(connectPlayerMessage);
        }
        processSnapshot();
        Packet             packet = Packet.Obtain();
        PlayerInputMessage pim    = new PlayerInputMessage(playerId, playerController.playerInput);

        cm.SendMessage(pim);

        Packet p = cm.BuildPacket();

        channel.Send(p);
    }