Exemplo n.º 1
0
        public bool GetButtonUp(GamepadButton button, GamepadIndex gamepad)
        {
            GamePadState state    = GetCurrentState(gamepad);
            GamePadState oldState = GetPreviousState(gamepad);

            return(!GetButton(button, state) && GetButton(button, oldState));
        }
Exemplo n.º 2
0
        public bool AnyInput(GamepadIndex gamepad)
        {
            if (m_adapter == null)
            {
                return(false);
            }

            for (int bi = 0; bi < NUMBER_OF_BUTTONS; bi++)
            {
                if (m_buttonStates[(int)gamepad, bi])
                {
                    return(true);
                }
            }

            for (int ai = 0; ai < NUMBER_OF_AXES; ai++)
            {
                if (m_axisStates[(int)gamepad, ai])
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        public bool GetButtonDown(GamepadButton button, GamepadIndex gamepad)
        {
            GamepadReading?state    = GetCurrentState(gamepad);
            GamepadReading?oldState = GetPreviousState(gamepad);

            return(GetButton(button, state) && !GetButton(button, oldState));
        }
Exemplo n.º 4
0
        protected override void OnAssignGamepadProfile(GamepadIndex gamepad)
        {
            if (!Adapter.IsConnected(gamepad))
            {
                return;
            }

            string gamepadName = Adapter.GetName(gamepad);

            for (int i = 0; i < m_profiles.Count; i++)
            {
                if (IsMatch(m_profiles[i], gamepadName))
                {
                    Adapter.SetProfile(gamepad, m_profiles[i].GamepadProfile);
                    Debug.LogFormat("Profile '{0}' assigned to '{1}'.", m_profiles[i].GamepadProfile.Name, gamepadName);
                    return;
                }
            }

            if (m_defaultProfile != null)
            {
                Adapter.SetProfile(gamepad, m_defaultProfile);
                Debug.LogFormat("No profile found for '{0}'. Assigning default profile '{1}'.", gamepadName, m_defaultProfile.Name);
            }
            else
            {
                Debug.LogFormat("No profile found for '{0}'.", gamepadName);
            }
        }
Exemplo n.º 5
0
        public static bool AnyInput(GamepadIndex gamepad)
        {
            PrintMissingAdapterWarningIfNecessary();

            GamepadStateService service = InputManager.GetService <GamepadStateService>();

            return(service != null?service.AnyInput(gamepad) : false);
        }
Exemplo n.º 6
0
 public static void SetVibration(GamepadVibration vibration, GamepadIndex gamepad)
 {
     PrintMissingAdapterWarningIfNecessary();
     if (Adapter != null)
     {
         Adapter.SetVibration(vibration, gamepad);
     }
 }
Exemplo n.º 7
0
        public GamepadDevice(GamepadIndex index)
        {
            if (index == GamepadIndex.Other)
            {
                throw new System.InvalidOperationException($"To use other indices, please use {nameof(GamepadDevice)}(int id) constructor directly.");
            }

            Id = (int)index;
        }
Exemplo n.º 8
0
        public static PlayerIndex ToPlayerIndex(this GamepadIndex gamepadIndex)
        {
            if ((int)gamepadIndex > (int)PlayerIndex.Four)
            {
                throw new System.InvalidOperationException($"{nameof(GamepadIndex)} '{gamepadIndex}' doesn't contains a valid associated {nameof(PlayerIndex)}.");
            }

            return((PlayerIndex)((int)gamepadIndex));
        }
Exemplo n.º 9
0
 public void ChangeGamepad(GamepadIndex gamepad)
 {
     foreach (var action in m_actions)
     {
         foreach (var binding in action.Bindings)
         {
             binding.GamepadIndex = gamepad;
         }
     }
 }
Exemplo n.º 10
0
        public void SetVibration(LumiVibration vibration, GamepadIndex gamepad)
        {
            Gamepad gamepadDevice = GetGamepad(gamepad);

            if (gamepadDevice != null)
            {
                gamepadDevice.Vibration = new WinVibration
                {
                    LeftMotor    = vibration.LeftMotor,
                    RightMotor   = vibration.RightMotor,
                    LeftTrigger  = vibration.LeftTrigger,
                    RightTrigger = vibration.RightTrigger
                };
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
 public void Copy(InputBinding source)
 {
     m_positive      = source.m_positive;
     m_negative      = source.m_negative;
     m_deadZone      = source.m_deadZone;
     m_gravity       = source.m_gravity;
     m_sensitivity   = source.m_sensitivity;
     m_snap          = source.m_snap;
     m_invert        = source.m_invert;
     m_type          = source.m_type;
     m_axis          = source.m_axis;
     m_joystick      = source.m_joystick;
     m_gamepadAxis   = source.m_gamepadAxis;
     m_gamepadButton = source.m_gamepadButton;
     m_gamepadIndex  = source.m_gamepadIndex;
 }
Exemplo n.º 13
0
        public LumiVibration GetVibration(GamepadIndex gamepad)
        {
            Gamepad gamepadDevice = GetGamepad(gamepad);

            if (gamepadDevice != null)
            {
                return(new LumiVibration
                {
                    LeftMotor = (float)gamepadDevice.Vibration.LeftMotor,
                    RightMotor = (float)gamepadDevice.Vibration.RightMotor,
                    LeftTrigger = (float)gamepadDevice.Vibration.LeftTrigger,
                    RightTrigger = (float)gamepadDevice.Vibration.RightTrigger
                });
            }

            return(new LumiVibration());
        }
Exemplo n.º 14
0
        public float GetAxis(GamepadAxis axis, GamepadIndex gamepad)
        {
            GamePadState state = GetCurrentState(gamepad);
            float        value = 0.0f;

            if (state.IsConnected)
            {
                switch (axis)
                {
                case GamepadAxis.LeftThumbstickX:
                    value = state.ThumbSticks.Left.X;
                    break;

                case GamepadAxis.LeftThumbstickY:
                    value = state.ThumbSticks.Left.Y;
                    break;

                case GamepadAxis.RightThumbstickX:
                    value = state.ThumbSticks.Right.X;
                    break;

                case GamepadAxis.RightThumbstickY:
                    value = state.ThumbSticks.Right.Y;
                    break;

                case GamepadAxis.LeftTrigger:
                    value = state.Triggers.Left;
                    break;

                case GamepadAxis.RightTrigger:
                    value = state.Triggers.Right;
                    break;

                case GamepadAxis.DPadX:
                    value = GetDPADState(gamepad).X;
                    break;

                case GamepadAxis.DPadY:
                    value = GetDPADState(gamepad).Y;
                    break;
                }
            }

            return(value);
        }
Exemplo n.º 15
0
        public float GetAxis(GamepadAxis axis, GamepadIndex gamepad)
        {
            GamepadReading?state = GetCurrentState(gamepad);
            double         value = 0.0;

            if (state.HasValue)
            {
                switch (axis)
                {
                case GamepadAxis.LeftThumbstickX:
                    value = state.Value.LeftThumbstickX;
                    break;

                case GamepadAxis.LeftThumbstickY:
                    value = state.Value.LeftThumbstickY;
                    break;

                case GamepadAxis.RightThumbstickX:
                    value = state.Value.RightThumbstickX;
                    break;

                case GamepadAxis.RightThumbstickY:
                    value = state.Value.RightThumbstickY;
                    break;

                case GamepadAxis.DPadX:
                    value = m_dpadState[(int)gamepad].X;
                    break;

                case GamepadAxis.DPadY:
                    value = m_dpadState[(int)gamepad].Y;
                    break;

                case GamepadAxis.LeftTrigger:
                    value = state.Value.LeftTrigger;
                    break;

                case GamepadAxis.RightTrigger:
                    value = state.Value.RightTrigger;
                    break;
                }
            }

            return((float)value);
        }
Exemplo n.º 16
0
        private XPlayerIndex ToPlayerIndex(GamepadIndex gamepad)
        {
            switch (gamepad)
            {
            case GamepadIndex.GamepadOne:
                return(XPlayerIndex.One);

            case GamepadIndex.GamepadTwo:
                return(XPlayerIndex.Two);

            case GamepadIndex.GamepadThree:
                return(XPlayerIndex.Three);

            case GamepadIndex.GamepadFour:
                return(XPlayerIndex.Four);

            default:
                return(XPlayerIndex.One);
            }
        }
Exemplo n.º 17
0
        public GenericGamepadProfile GetProfile(GamepadIndex gamepad)
        {
            switch (gamepad)
            {
            case GamepadIndex.GamepadOne:
                return(m_gamepadOne);

            case GamepadIndex.GamepadTwo:
                return(m_gamepadTwo);

            case GamepadIndex.GamepadThree:
                return(m_gamepadThree);

            case GamepadIndex.GamepadFour:
                return(m_gamepadFour);

            default:
                throw new System.ArgumentException(string.Format("Gamepad '{0}' is not valid.", gamepad), "gamepad");
            }
        }
Exemplo n.º 18
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");
            }
        }
Exemplo n.º 19
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);
            }
        }
Exemplo n.º 20
0
        public float GetAxisRaw(GamepadAxis axis, GamepadIndex gamepad)
        {
            float value = GetAxis(axis, gamepad);

            return(Mathf.Approximately(value, 0) ? 0.0f : Mathf.Sign(value));
        }
Exemplo n.º 21
0
 public GamepadState(GamepadIndex userIndex)
 {
     UserIndex = userIndex;
     Controller = new Controller((UserIndex)userIndex);
 }
Exemplo n.º 22
0
 public bool IsConnected(GamepadIndex gamepad)
 {
     return(m_gamepadStatus[(int)gamepad].IsConnected);
 }
Exemplo n.º 23
0
 public string GetName(GamepadIndex gamepad)
 {
     return(m_gamepadStatus[(int)gamepad].Name);
 }
Exemplo n.º 24
0
 public GenericGamepadProfile this[GamepadIndex gamepad]
 {
     get { return(GetProfile(gamepad)); }
 }
Exemplo n.º 25
0
 public GamepadCapabilities(GamepadIndex index) : this((int)index)
 {
 }
Exemplo n.º 26
0
 public void SetVibration(GamepadVibration vibration, GamepadIndex gamepad)
 {
 }
 public bool IsConnected(GamepadIndex gamepad)
 {
     return(m_joystickState[(int)gamepad]);
 }
Exemplo n.º 28
0
 public GamepadVibration GetVibration(GamepadIndex gamepad)
 {
     return(new GamepadVibration());
 }
Exemplo n.º 29
0
 public bool GetButtonUp(GamepadButton button, GamepadIndex gamepad)
 {
     return(false);
 }
Exemplo n.º 30
0
 public GamepadVibration GetVibration(GamepadIndex gamepad)
 {
     return(GamepadVibration.None);
 }
Exemplo n.º 31
0
 public float GetAxisRaw(GamepadAxis axis, GamepadIndex gamepad)
 {
     return(0);
 }