TraceRacer.InputAction.Evaluate C# (CSharp) Method

Evaluate() public method

Evaluates the action against a given InputState.
public Evaluate ( InputState state, PlayerIndex controllingPlayer, PlayerIndex &player ) : bool
state InputState The InputState to test for the action.
controllingPlayer PlayerIndex The player to test, or null to allow any player.
player PlayerIndex If controllingPlayer is null, this is the player that performed the action.
return bool
        public bool Evaluate(InputState state, PlayerIndex? controllingPlayer, out PlayerIndex player)
        {
            // Figure out which delegate methods to map from the state which takes care of our "newPressOnly" logic
            ButtonPress buttonTest;
            KeyPress keyTest;
            if (newPressOnly)
            {
                buttonTest = state.IsNewButtonPress;
                keyTest = state.IsNewKeyPress;
            }
            else
            {
                buttonTest = state.IsButtonPressed;
                keyTest = state.IsKeyPressed;
            }

            // Now we simply need to invoke the appropriate methods for each button and key in our collections
            foreach (Buttons button in buttons)
            {
                if (buttonTest(button, controllingPlayer, out player))
                    return true;
            }
            foreach (Keys key in keys)
            {
                if (keyTest(key, controllingPlayer, out player))
                    return true;
            }

            // If we got here, the action is not matched
            player = PlayerIndex.One;
            return false;
        }