CharacterInput.Parse C# (CSharp) Method

Parse() public method

Ask to update input from Unity's Input
public Parse ( int inputState ) : void
inputState int
return void
    public void Parse(int inputState)
    {
        if (isLocalPlayer)
        {
            currentInput.inputState = inputState;

            currentInput.setInputHorizontal(Input.GetAxis("Horizontal"));
            currentInput.setInputVertical(Input.GetAxis("Vertical"));
            currentInput.setPitch(cameraAim.pitch);
            currentInput.setYaw(cameraAim.yaw);

            currentInput.inputJump = Input.GetButton("Jump");
            currentInput.inputFire = Input.GetButton("Fire1");
            currentInput.inputAim  = Input.GetButton("Fire2");
            currentInput.inputRun  = Input.GetButton("Run");
        }
    }

Usage Example

Example #1
0
    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)
        {
            //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 > WARNING_CLIENT_WAITING_STATES)
            {
                Debug.LogWarning("[NetworkInput]: States starting pulling up, are network condition bad?");
            }
            if (inputStates.Count > MAX_CLIENT_WAITING_STATES)
            {
                Debug.LogError("Too many waiting states, starting to drop frames");
            }
            while (inputStates.Count > MAX_CLIENT_WAITING_STATES)
            {
                inputStates.Dequeue();
            }
            //Client: Send every sendInterval
            if (isServer && isLocalPlayer || nextSendTime < Time.time)
            {
                CmdSetServerInput(inputStates.ToArray(), transform.position);
                nextSendTime = Time.time + 0.33f;
            }
        }
    }
CharacterInput