Example #1
0
 public void Monitor(
     JoystickConfiguration joystickConfiguration,
     KeyboardConfiguration keyboardConfiguration
     )
 {
     MonitorJoystickInput(joystickConfiguration);
     MonitorKeyboardInput(keyboardConfiguration);
 }
Example #2
0
    public void MonitorJoystickInput(JoystickConfiguration configuration)
    {
        JoystickInput = Joystick.GetInput2D(
            configuration.Deadzone,
            configuration.HorizontalAxisName,
            configuration.VerticalAxisName
            );

        if (JoystickInput.magnitude != 0.0f)
        {
            if (IsMonitoringKeyboard())
            {
                CurrentControlScheme = ControlScheme.JOYSTICK;
            }

            float joystickInputX = JoystickInput.x;

            if (joystickInputX > 0)
            {
                if (IsMovingLeft())
                {
                    CurrentMovementState &= ~MovementState.LEFT;
                }

                CurrentMovementState |= MovementState.RIGHT;
            }
            else if (joystickInputX < 0)
            {
                if (IsMovingRight())
                {
                    CurrentMovementState &= ~MovementState.RIGHT;
                }

                CurrentMovementState |= MovementState.LEFT;
            }
            else if (joystickInputX == 0.0f)
            {
                CurrentMovementState &= ~(MovementState.LEFT | MovementState.RIGHT);
            }

            float joystickInputY = JoystickInput.y;

            if (joystickInputY > 0)
            {
                if (IsMovingDown())
                {
                    CurrentMovementState &= ~MovementState.DOWN;
                }

                CurrentMovementState |= MovementState.UP;
            }
            else if (joystickInputY < 0)
            {
                if (IsMovingUp())
                {
                    CurrentMovementState &= ~MovementState.UP;
                }

                CurrentMovementState |= MovementState.DOWN;
            }
            else if (joystickInputY == 0.0f)
            {
                CurrentMovementState &= ~(MovementState.UP | MovementState.DOWN);
            }
        }
        else
        {
            CurrentMovementState = MovementState.NEUTRAL;
        }
    }