コード例 #1
0
    void Start()
    {
        if (peerType == EasyWiFiConstants.PEER_TYPE.Client)
        {
            lastSendTime = Time.realtimeSinceStartup;

            //set the rate
            switch (clientMaxSendRate)
            {
            case EasyWiFiConstants.CONTROLLERDATA_MAX_SEND_RATE.CapAt30Hz:
                maxRate = .033333333f;
                break;

            case EasyWiFiConstants.CONTROLLERDATA_MAX_SEND_RATE.CapAt60Hz:
                maxRate = .016666666f;
                break;

            case EasyWiFiConstants.CONTROLLERDATA_MAX_SEND_RATE.CapAt90Hz:
                maxRate = .011111111f;
                break;

            case EasyWiFiConstants.CONTROLLERDATA_MAX_SEND_RATE.SendAsFastAsPossible:
                maxRate = 0f;
                break;

            case EasyWiFiConstants.CONTROLLERDATA_MAX_SEND_RATE.SendInfrequentlyOncePerSecond:
                maxRate = 1f;
                break;

            default:
                maxRate = 0f;
                break;
            }


            //There can be a timing issue between when the server has been discovered but we might not be ready yet
            //to transmit our inventory.  Becuase this script executes in start and registrations in awake all the local registrations have now take place
            EasyWiFiController.readyToTransmitInventory = true;

            if (!transmittedInventory && (EasyWiFiController.clientState != EasyWiFiConstants.CURRENT_CLIENT_STATE.Broadcasting && EasyWiFiController.clientState != EasyWiFiConstants.CURRENT_CLIENT_STATE.NotConnected))
            {
                //depending on the order in which client and server are started check our state and send inventory immediately
                EasyWiFiController.sendControllerInventory(EasyWiFiController.createInventoryMessage());
                EasyWiFiController.clientState = EasyWiFiConstants.CURRENT_CLIENT_STATE.SendingInventory;
            }

            if (heartbeatTimeout > 0f)
            {
                InvokeRepeating("checkHeartbeatForTimeout", heartbeatTimeout, heartbeatTimeout);
            }
        }
        else
        {
            if (serverSendBackchannel)
            {
                EasyWiFiController.readyToTransmitBackchannel = true;
            }
            if (serverSendHeartbeatRate > 0f)
            {
                InvokeRepeating("sendServerHeartbeat", serverSendHeartbeatRate, serverSendHeartbeatRate);
            }
            if (clientTimeout > 0f)
            {
                InvokeRepeating("checkForClientTimeout", clientTimeout, clientTimeout);
            }
        }
    }