コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        // if data should be communicated.
        if (dataComm)
        {
            // checks to update data
            bool sendData = false;

            if (useIntervals && intervalTimer != null) // using intervals
            {
                // checks to see if the interval has ended.
                intervalTimer.intervalLength = intervalLength; // updates to current interval length
                sendData = intervalTimer.IntervalEnded();
            }
            else // not using intervals
            {
                sendData = true;
            }


            if (isMaster && server.server.IsRunning()) // this player is the server
            {
                // gets the data from the clients.
                ReceiveDataFromClients();

                // sends the data from the clients.
                if (sendData)
                {
                    SendDataToClients();
                }
            }
            else if (!isMaster && client.client.IsRunning()) // this player is the client.
            {
                // sends the data to the server
                if (sendData)
                {
                    SendDataToServer();
                }

                // receives data from the server.
                ReceiveDataFromServer();
            }
        }
    }