コード例 #1
0
    private void FixedUpdate()
    {
        if (NUServer.started)         //Is Server!
        {
            //Send Game-state to everyone online
            Packet stateData = new Packet(GetStateMsg(), NUServer.GetConnectedClients());
            NUServer.SendUnreliable(stateData);
        }

        // Test for multipart (really big) packet
        if (Input.GetKeyUp(KeyCode.I))
        {
            byte[] randomBuffer = new byte[8192];
            for (int i = 0; i < 8192; i++)
            {
                randomBuffer[i] = (byte)(Random.Range(0, 255));
            }

            if (NUServer.started)
            {
                Packet multipartTestPacket = new Packet(randomBuffer,
                                                        NUServer.GetConnectedClients(), Packet.TypeFlag.DATA);
                NUServer.SendReliable(multipartTestPacket);
            }
            else if (NUClient.connected)
            {
                Packet multipartTestPacket = new Packet(randomBuffer);
                NUClient.SendReliable(multipartTestPacket);
            }
        }

        // Test for sequenced packet
        if (Input.GetKeyUp(KeyCode.J))
        {
            Packet firstPacket  = new Packet("First", packetId: NUUtilities.GeneratePacketId());
            Packet secondPacket = new Packet("Second", packetId: NUUtilities.GeneratePacketId());
            Packet thirdPacket  = new Packet("Third", packetId: NUUtilities.GeneratePacketId());
            Debug.LogError("Third");
            Debug.LogError("Second");
            Debug.LogError("First");
            if (NUServer.started)
            {
                thirdPacket.OverrideDestination(NUServer.GetConnectedClients());
                NUServer.SendReliableSequenced(thirdPacket);                    //Send third first
                secondPacket.OverrideDestination(NUServer.GetConnectedClients());
                NUServer.SendReliableSequenced(secondPacket);                   //Send second second
                firstPacket.OverrideDestination(NUServer.GetConnectedClients());
                NUServer.SendReliableSequenced(firstPacket);                    //Then first third
            }
            else if (NUClient.connected)
            {
                NUClient.SendReliableSequenced(thirdPacket);                    //Send third first
                NUClient.SendReliableSequenced(secondPacket);                   //Send second second
                NUClient.SendReliableSequenced(firstPacket);                    //Then first third
            }
        }
    }
コード例 #2
0
    public void Spawn()
    {
        if (inputField.text.Length == 0)
        {
            inputField.Select();
            return;
        }
        Packet spawnPacket = new Packet("Spw|" + inputField.text);

        NUClient.SendReliable(spawnPacket);
        guiCanvas.SetActive(false);
    }
コード例 #3
0
    private void Update()
    {
        if (!NUClient.connected)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            NUClient.SendReliable(new Packet("Jmp"));
        }

        //Stream Player Input
        Vector3 input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

        input *= (Time.deltaTime * 5.0f);

        string inpMsg = "Inp|";

        inpMsg += input.x.ToString("R") + ":" + input.y.ToString("R") + ":" + input.z.ToString("R");
        Packet inpPacket = new Packet(inpMsg);

        NUClient.SendUnreliable(inpPacket);
    }