示例#1
0
    void Update()
    {
        if (_state == State.Advance)
        {
            SendFrame();
            _state = State.Receive;
        }

        if (_state == State.Receive)
        {
            if (inputListener.ReceivedBytes())
            {
                if (inputListener.currentFrameCounter != sensorConverter.frameCounter)
                {
                    Debug.LogFormat("Received wrong frame counter ({0} instead of {1}).",
                                    inputListener.currentFrameCounter,
                                    sensorConverter.frameCounter);
                }
                else
                {
                    _state = State.Advance;
                    sensorConverter.AdvanceFrameCounter();
                }
            }

            if (IsTimedOut())
            {
                Debug.LogFormat("{1,5} Timeout. sensorConverter.frameCounter={0}", sensorConverter.frameCounter, Time.realtimeSinceStartup);
                SendFrame();
            }
        }
    }