Exemplo n.º 1
0
        private void FixedUpdate()
        {
            //Client: Please read: http://forum.unity3d.com/threads/tips-for-server-authoritative-player-movement.199538/

            //Client: Only client run simulation in realtime for the player to see

            if (!isLocalPlayer)
            {
                return;
            }

            //Client: start a new state
            _localInputState = _localInputState + 1;

            //Client: Updates camera
            _cameraMouseAim.RunUpdate(Time.fixedDeltaTime);
            _cameraAimPoint.RunUpdate(Time.fixedDeltaTime);

            //Client: gathers user input state
            _characterInput.Parse(_localInputState);

            //Client: add new input to the list
            _inputStates.Enqueue(_characterInput.CurrentInput);

            //Client: execute simulation on local data
            _characterMovement.RunUpdate(Time.fixedDeltaTime);
            _characterRotation.RunUpdate(Time.fixedDeltaTime);

            //Client: Trim commands to 25 and send commands to server
            if (_inputStates.Count > WarningClientWaitingStates)
            {
                Debug.LogWarning("[NetworkInput]: States starting pulling up, are network condition bad?");
            }

            if (_inputStates.Count > MaxClientWaitingStates)
            {
                Debug.LogError("Too many waiting states, starting to drop frames");
            }

            while (_inputStates.Count > MaxClientWaitingStates)
            {
                _inputStates.Dequeue();
            }

            //Client: Send every sendInterval
            if (isServer && isLocalPlayer || _nextSendTime < Time.time)
            {
                CmdSetServerInput(_inputStates.ToArray(), transform.position);
                _nextSendTime = Time.time + 0.33f;
            }
        }