예제 #1
0
        private void UpdateDPadVertical(float deltaTime)
        {
            for (int i = 0; i < m_dpadState.Length; i++)
            {
                GenericGamepadProfile profile = GetProfile(i);
                bool upPressed = false, downPressed = false;

                if (profile != null && profile.DPadType == GamepadDPadType.Button)
                {
                    upPressed   = GetButton(profile.DPadUpButton, i);
                    downPressed = GetButton(profile.DPadDownButton, i);
                }

                if (upPressed)
                {
                    if (m_dpadState[i].Y < InputBinding.AXIS_NEUTRAL && m_dpadSnap)
                    {
                        m_dpadState[i].Y = InputBinding.AXIS_NEUTRAL;
                    }

                    m_dpadState[i].Y += m_dpadSensitivity * deltaTime;
                    if (m_dpadState[i].Y > InputBinding.AXIS_POSITIVE)
                    {
                        m_dpadState[i].Y = InputBinding.AXIS_POSITIVE;
                    }
                }
                else if (downPressed)
                {
                    if (m_dpadState[i].Y > InputBinding.AXIS_NEUTRAL && m_dpadSnap)
                    {
                        m_dpadState[i].Y = InputBinding.AXIS_NEUTRAL;
                    }

                    m_dpadState[i].Y -= m_dpadSensitivity * deltaTime;
                    if (m_dpadState[i].Y < InputBinding.AXIS_NEGATIVE)
                    {
                        m_dpadState[i].Y = InputBinding.AXIS_NEGATIVE;
                    }
                }
                else
                {
                    if (m_dpadState[i].Y < InputBinding.AXIS_NEUTRAL)
                    {
                        m_dpadState[i].Y += m_dpadGravity * deltaTime;
                        if (m_dpadState[i].Y > InputBinding.AXIS_NEUTRAL)
                        {
                            m_dpadState[i].Y = InputBinding.AXIS_NEUTRAL;
                        }
                    }
                    else if (m_dpadState[i].Y > InputBinding.AXIS_NEUTRAL)
                    {
                        m_dpadState[i].Y -= m_dpadGravity * deltaTime;
                        if (m_dpadState[i].Y < InputBinding.AXIS_NEUTRAL)
                        {
                            m_dpadState[i].Y = InputBinding.AXIS_NEUTRAL;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void UpdateDPadHorizontal(float deltaTime)
        {
            for (int i = 0; i < m_dpadState.Length; i++)
            {
                GenericGamepadProfile profile = GetProfile(i);
                bool rightPressed = false, leftPressed = false;

                if (profile != null && profile.DPadType == GamepadDPadType.Button)
                {
                    rightPressed = GetButton(profile.DPadRightButton, i);
                    leftPressed  = GetButton(profile.DPadLeftButton, i);
                }

                if (rightPressed)
                {
                    if (m_dpadState[i].X < InputBinding.AXIS_NEUTRAL && m_dpadSnap)
                    {
                        m_dpadState[i].X = InputBinding.AXIS_NEUTRAL;
                    }

                    m_dpadState[i].X += m_dpadSensitivity * deltaTime;
                    if (m_dpadState[i].X > InputBinding.AXIS_POSITIVE)
                    {
                        m_dpadState[i].X = InputBinding.AXIS_POSITIVE;
                    }
                }
                else if (leftPressed)
                {
                    if (m_dpadState[i].X > InputBinding.AXIS_NEUTRAL && m_dpadSnap)
                    {
                        m_dpadState[i].X = InputBinding.AXIS_NEUTRAL;
                    }

                    m_dpadState[i].X -= m_dpadSensitivity * deltaTime;
                    if (m_dpadState[i].X < InputBinding.AXIS_NEGATIVE)
                    {
                        m_dpadState[i].X = InputBinding.AXIS_NEGATIVE;
                    }
                }
                else
                {
                    if (m_dpadState[i].X < InputBinding.AXIS_NEUTRAL)
                    {
                        m_dpadState[i].X += m_dpadGravity * deltaTime;
                        if (m_dpadState[i].X > InputBinding.AXIS_NEUTRAL)
                        {
                            m_dpadState[i].X = InputBinding.AXIS_NEUTRAL;
                        }
                    }
                    else if (m_dpadState[i].X > InputBinding.AXIS_NEUTRAL)
                    {
                        m_dpadState[i].X -= m_dpadGravity * deltaTime;
                        if (m_dpadState[i].X < InputBinding.AXIS_NEUTRAL)
                        {
                            m_dpadState[i].X = InputBinding.AXIS_NEUTRAL;
                        }
                    }
                }
            }
        }
예제 #3
0
        public float GetAxis(GamepadAxis axis, GamepadIndex gamepad)
        {
            GenericGamepadProfile profile = GetProfile(gamepad);

            if (profile == null)
            {
                return(0.0f);
            }

            int joyID = (int)gamepad, axisID = -1;

            switch (axis)
            {
            case GamepadAxis.LeftThumbstickX:
                axisID = profile.LeftStickXAxis;
                break;

            case GamepadAxis.LeftThumbstickY:
                axisID = profile.LeftStickYAxis;
                break;

            case GamepadAxis.RightThumbstickX:
                axisID = profile.RightStickXAxis;
                break;

            case GamepadAxis.RightThumbstickY:
                axisID = profile.RightStickYAxis;
                break;

            case GamepadAxis.DPadX:
                axisID = profile.DPadXAxis;
                break;

            case GamepadAxis.DPadY:
                axisID = profile.DPadYAxis;
                break;

            case GamepadAxis.LeftTrigger:
                axisID = profile.LeftTriggerAxis;
                break;

            case GamepadAxis.RightTrigger:
                axisID = profile.RightTriggerAxis;
                break;
            }

            return(axisID >= 0 ? Input.GetAxis(m_axisNameLookupTable[joyID * InputBinding.MAX_JOYSTICK_AXES + axisID]) : 0.0f);
        }
예제 #4
0
        private void UpdateTriggers(float deltaTime)
        {
            for (int i = 0; i < m_triggerState.Length; i++)
            {
                GenericGamepadProfile profile = GetProfile(i);
                bool rightPressed = false, leftPressed = false;

                if (profile != null && profile.TriggerType == GamepadTriggerType.Button)
                {
                    rightPressed = GetButton(profile.RightTriggerButton, i);
                    leftPressed  = GetButton(profile.LeftTriggerButton, i);
                }

                if (rightPressed)
                {
                    m_triggerState[i].Right += m_triggerSensitivity * deltaTime;
                    if (m_triggerState[i].Right > InputBinding.AXIS_POSITIVE)
                    {
                        m_triggerState[i].Right = InputBinding.AXIS_POSITIVE;
                    }
                }
                else
                {
                    m_triggerState[i].Right -= m_triggerGravity * deltaTime;
                    if (m_triggerState[i].Right < InputBinding.AXIS_NEUTRAL)
                    {
                        m_triggerState[i].Right = InputBinding.AXIS_NEUTRAL;
                    }
                }

                if (leftPressed)
                {
                    m_triggerState[i].Left += m_triggerSensitivity * deltaTime;
                    if (m_triggerState[i].Left > InputBinding.AXIS_POSITIVE)
                    {
                        m_triggerState[i].Left = InputBinding.AXIS_POSITIVE;
                    }
                }
                else
                {
                    m_triggerState[i].Left -= m_triggerGravity * deltaTime;
                    if (m_triggerState[i].Left < InputBinding.AXIS_NEUTRAL)
                    {
                        m_triggerState[i].Left = InputBinding.AXIS_NEUTRAL;
                    }
                }
            }
        }
예제 #5
0
        private void UpdateDPadButtons()
        {
            for (int i = 0; i < m_dpadState.Length; i++)
            {
                GenericGamepadProfile profile = GetProfile(i);
                float x = 0.0f, y = 0.0f;

                if (profile != null && profile.DPadType == GamepadDPadType.Axis)
                {
                    x = Input.GetAxis(m_axisNameLookupTable[i * InputBinding.MAX_JOYSTICK_AXES + profile.DPadXAxis]);
                    y = Input.GetAxis(m_axisNameLookupTable[i * InputBinding.MAX_JOYSTICK_AXES + profile.DPadYAxis]);
                }

                m_dpadState[i].Up    = GetNewDPadButtonState(y >= 0.9f, m_dpadState[i].Up);
                m_dpadState[i].Down  = GetNewDPadButtonState(y <= -0.9f, m_dpadState[i].Down);
                m_dpadState[i].Left  = GetNewDPadButtonState(x <= -0.9f, m_dpadState[i].Left);
                m_dpadState[i].Right = GetNewDPadButtonState(x >= 0.9f, m_dpadState[i].Right);
            }
        }
예제 #6
0
        public void SetProfile(GamepadIndex gamepad, GenericGamepadProfile profile)
        {
            switch (gamepad)
            {
            case GamepadIndex.GamepadOne:
                m_gamepadOne = profile;
                break;

            case GamepadIndex.GamepadTwo:
                m_gamepadTwo = profile;
                break;

            case GamepadIndex.GamepadThree:
                m_gamepadThree = profile;
                break;

            case GamepadIndex.GamepadFour:
                m_gamepadFour = profile;
                break;

            default:
                throw new System.ArgumentException(string.Format("Gamepad '{0}' is not valid.", gamepad), "gamepad");
            }
        }
예제 #7
0
        public bool GetButtonUp(GamepadButton button, GamepadIndex gamepad)
        {
            GenericGamepadProfile profile = GetProfile(gamepad);

            if (profile == null)
            {
                return(false);
            }

            switch (button)
            {
            case GamepadButton.LeftStick:
                return(GetButtonUp(profile.LeftStickButton, (int)gamepad));

            case GamepadButton.RightStick:
                return(GetButtonUp(profile.RightStickButton, (int)gamepad));

            case GamepadButton.LeftBumper:
                return(GetButtonUp(profile.LeftBumperButton, (int)gamepad));

            case GamepadButton.RightBumper:
                return(GetButtonUp(profile.RightBumperButton, (int)gamepad));

            case GamepadButton.DPadUp:
                return(profile.DPadType == GamepadDPadType.Button ?
                       GetButtonUp(profile.DPadUpButton, (int)gamepad) :
                       m_dpadState[(int)gamepad].Up == ButtonState.JustReleased);

            case GamepadButton.DPadDown:
                return(profile.DPadType == GamepadDPadType.Button ?
                       GetButtonUp(profile.DPadUpButton, (int)gamepad) :
                       m_dpadState[(int)gamepad].Down == ButtonState.JustReleased);

            case GamepadButton.DPadLeft:
                return(profile.DPadType == GamepadDPadType.Button ?
                       GetButtonUp(profile.DPadUpButton, (int)gamepad) :
                       m_dpadState[(int)gamepad].Left == ButtonState.JustReleased);

            case GamepadButton.DPadRight:
                return(profile.DPadType == GamepadDPadType.Button ?
                       GetButtonUp(profile.DPadUpButton, (int)gamepad) :
                       m_dpadState[(int)gamepad].Right == ButtonState.JustReleased);

            case GamepadButton.Back:
                return(GetButtonUp(profile.BackButton, (int)gamepad));

            case GamepadButton.Start:
                return(GetButtonUp(profile.StartButton, (int)gamepad));

            case GamepadButton.ActionBottom:
                return(GetButtonUp(profile.ActionBottomButton, (int)gamepad));

            case GamepadButton.ActionRight:
                return(GetButtonUp(profile.ActionRightButton, (int)gamepad));

            case GamepadButton.ActionLeft:
                return(GetButtonUp(profile.ActionLeftButton, (int)gamepad));

            case GamepadButton.ActionTop:
                return(GetButtonUp(profile.ActionTopButton, (int)gamepad));

            default:
                return(false);
            }
        }