示例#1
0
        /// <summary>
        /// Handles the input change of the local player.
        /// Not all input is specified in the parameters.
        /// </summary>
        public void UpdateLocalInput(Vector3 trackedPosition)
        {
            Vector3 movementInput = new Vector3(Input.GetAxisRaw("Rightward"),
                                                Input.GetAxisRaw("Upward"), Input.GetAxisRaw("Forward"));

            byte[] payload = new byte[(BotState.InputSerializedBitsSize + 7) / 8];
            _sharedBuffer.ClearContents(payload);
            BotState.SerializePlayerInput(_sharedBuffer, movementInput, trackedPosition);

            if (NetworkUtils.IsServer)
            {
                BotCache.SetExtra(NetworkUtils.LocalId, BotCache.Extra.NetworkedPhysics, payload);
            }
            else
            {
                NetworkClient.UdpPayload = payload;
                long key = DoubleProtocol.TimeMillis + Mathf.RoundToInt(NetworkClient.UdpNetDelay + AverageNonNetDelayMillis);
                _guessedInputs.Remove(key);
                _guessedInputs.Add(key, new GuessedInput(movementInput));
            }
        }