Exemplo n.º 1
0
 /// <summary>
 /// Returns true if specified <paramref name="button"/> pressed on gamepad of specified player
 /// </summary>
 /// <param name="button">Button to check</param>
 /// <param name="gamepadNumber">Gamepad number</param>
 /// <returns></returns>
 public static bool IsButtonDown(GamepadButtons button, GamepadNumbers gamepadNumber)
 {
     if (GamepadInstance.IsDeviceConnected)
     {
         if (GamepadInstance.IsSupported)
         {
             if (GetState(gamepadNumber).Gamepad.Buttons == (GetState(gamepadNumber).Gamepad.Buttons | (XInput.GamepadButtonFlags)button))
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets values of specified thumbstick like X and Y axis etc
        /// </summary>
        /// <param name="stick">Stick to get values</param>
        /// <param name="gamepadNumber">Gamepad number</param>
        /// <returns></returns>
        public static GamepadStickState GetStickValue(GamepadSticks stick, GamepadNumbers gamepadNumber)
        {
            if (GamepadInstance.IsDeviceConnected)
            {
                if (GamepadInstance.IsSupported)
                {
                    XInput.State      state        = GetState(gamepadNumber);
                    GamepadStickState gamepadStick = GamepadStickState.Empty;
                    switch (stick)
                    {
                    case GamepadSticks.LeftStick:
                        gamepadStick.IsDown = IsButtonDown(GamepadButtons.LeftStick);
                        gamepadStick.X      = state.Gamepad.LeftThumbX;
                        gamepadStick.Y      = state.Gamepad.LeftThumbY;
                        break;

                    case GamepadSticks.RightStick:
                        gamepadStick.IsDown = IsButtonDown(GamepadButtons.LeftStick);
                        gamepadStick.X      = state.Gamepad.LeftThumbX;
                        gamepadStick.Y      = state.Gamepad.LeftThumbY;
                        break;
                    }
                    return(gamepadStick);
                }
                else
                {
                    return(GamepadStickState.Empty);
                }
            }
            else
            {
                return(GamepadStickState.Empty);
            }
        }
Exemplo n.º 3
0
        private static XInput.State GetState(GamepadNumbers gamepadNumber)
        {
            try
            {
                if (Gamepad.GamepadInstance.IsSupported)
                {
                    XInput.State state = GamepadInstance.EmptyState;
                    switch (gamepadNumber)
                    {
                    case GamepadNumbers.One:
                        state = GamepadInstance.Gamepad1.GetState();
                        break;

                    case GamepadNumbers.Two:
                        state = GamepadInstance.Gamepad2.GetState();
                        break;

                    case GamepadNumbers.Three:
                        state = GamepadInstance.Gamepad3.GetState();
                        break;

                    case GamepadNumbers.Four:
                        state = GamepadInstance.Gamepad4.GetState();
                        break;
                    }
                    GamepadInstance.IsDeviceConnected = true;
                    return(state);
                }
                else
                {
                    return(GamepadInstance.EmptyState);
                }
            }
            catch (Exception ex)
            {
                Debugging.LogException(LogEntryType.Warning, ex);
                GamepadInstance.IsDeviceConnected = false;
                return(GamepadInstance.EmptyState);
            }
        }