Пример #1
0
        public void Update()
        {
            // Saving previous state
            PreviousState.Copy(CurrentState);

            // Getting raw gamepad state
            uint result = XInputInterface.XInputGamePadGetState(playerIndex, out rawState);

            // Zeroing raw state if the controller is not connected
            if (result != XInputInterface.RESULT_SUCCESS)
            {
                rawState.dwPacketNumber        = 0;
                rawState.Gamepad.wButtons      = 0;
                rawState.Gamepad.bLeftTrigger  = 0;
                rawState.Gamepad.bRightTrigger = 0;
                rawState.Gamepad.sThumbLX      = 0;
                rawState.Gamepad.sThumbLY      = 0;
                rawState.Gamepad.sThumbRX      = 0;
                rawState.Gamepad.sThumbRY      = 0;
            }

            // Updating cycle related flags
            IsConnected = result == XInputInterface.RESULT_SUCCESS;
            HasChanges  = PacketNumber != rawState.dwPacketNumber;

            // Quitting early if we have no changes
            if (!HasChanges)
            {
                return;
            }

            // Updating current state
            PacketNumber = rawState.dwPacketNumber;
            CurrentState.Apply(rawState);
        }
        private void FindControllers()
        {
            if (controller != null)
            {
                // If we already have a controller, skip the search
                return;
            }

            int playerIndex = -1;

            if (XInputInterface.IsGamePadConnected(GamePad.PLAYER_INDEX_ONE))
            {
                playerIndex = (int)GamePad.PLAYER_INDEX_ONE;
            }
            else if (XInputInterface.IsGamePadConnected(GamePad.PLAYER_INDEX_TWO))
            {
                playerIndex = (int)GamePad.PLAYER_INDEX_TWO;
            }
            else if (XInputInterface.IsGamePadConnected(GamePad.PLAYER_INDEX_THREE))
            {
                playerIndex = (int)GamePad.PLAYER_INDEX_THREE;
            }
            else if (XInputInterface.IsGamePadConnected(GamePad.PLAYER_INDEX_FOUR))
            {
                playerIndex = (int)GamePad.PLAYER_INDEX_FOUR;
            }

            if (playerIndex != -1)
            {
                Console.WriteLine($"XInput controller found: {playerIndex}");

                controller = new XInputController((uint)playerIndex);
                OnDeviceConnectionStateChanged(controller, true);
            }
        }
Пример #3
0
 public void SetVibration(float leftMotor, float rightMotor)
 {
     XInputInterface.XInputGamePadSetState(playerIndex, leftMotor, rightMotor);
 }