コード例 #1
0
 // Function for sending a spawn request to the server from a client
 public bool RequestSpawn(int x, int y, int z)
 {
     if (!isHost)
     {
         BuildCoder encoder = new BuildCoder(52);
         encoder.AddCube(x, y, z);
         Send(hostId, myReliableChannelId, encoder.getArray());         // Send message to VR server
         return(true);
     }
     return(false);
 }
コード例 #2
0
    // Send spawn command to AR players
    public void SendSpawn(int x, int y, int z)
    {
        BuildCoder encoder = new BuildCoder(52);

        encoder.AddCube(x, y, z);
        Debug.Log("There are now " + encoder.getCount() + " items");
        foreach (KeyValuePair <int, GameObject> player in ARPlayers)
        {
            Send(player.Key, myReliableChannelId, encoder.getArray());                                      // Send serialized information down the reliable channel
        }
    }
コード例 #3
0
    void Update()
    {
        if (networkInitialised)
        {
            int              recHostId;                         // Own id
            int              connectionId;                      // sender Id
            int              channelId;                         // channel Id
            int              bufferSize = 52;                   // buffer size
            byte[]           recBuffer  = new byte[bufferSize]; //Receiving buffer
            int              dataSize;                          //data size
            byte             error;                             // error byte
            NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
            switch (recData)
            {
            case NetworkEventType.Nothing:
                break;

            case NetworkEventType.ConnectEvent:     //AR connects
                Debug.Log("Connection request from id: " + connectionId + " Received");

                //if a connection is received and this is the host, then handle the connection
                if (isHost)
                {
                    HandleConnect(connectionId);
                }
                break;

            //if data is received
            case NetworkEventType.DataEvent:
                Debug.Log("Data Received");

                //create coder for the purpose of decoding
                BuildCoder decoder = new BuildCoder(recBuffer);
                if (channelId == myReliableChannelId)
                {
                    for (int i = 0; i < decoder.getCount(); i++)
                    {
                        int x = decoder.GetX(i);
                        int y = decoder.GetY(i);
                        int z = decoder.GetZ(i);

                        if (!grid.CubeExists(x, y, z))
                        {
                            grid.AddCube(x, y, z, 0.0f, 0.0f);
                            if (isHost)
                            {
                                SendSpawn(x, y, z);
                            }
                        }
                    }
                }
                else
                {     // It's info on AR player pos
                    HandleARPosition(connectionId, decoder.GetPosition(1), decoder.GetRotation(1));
                }

                break;

            case NetworkEventType.DisconnectEvent:     //AR disconnects
                HandleClientDisconnect(connectionId);
                Debug.Log("Disconnect Received");
                break;
            }
        }
    }