minesweeper_game/Library/PackageCache/com.unity.inputsystem@e2c83221d2dc/InputSystem/Plugins/XInput/XInputSupport.cs
2025-03-15 14:30:26 -04:00

65 lines
2.9 KiB
C#

////TODO: add support for Windows.Gaming.Input.Gamepad (including the trigger motors)
using UnityEngine.InputSystem.Layouts;
namespace UnityEngine.InputSystem.XInput
{
/// <summary>
/// Adds support for XInput controllers.
/// </summary>
#if UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION
public
#else
internal
#endif
static class XInputSupport
{
public static void Initialize()
{
// Base layout for Xbox-style gamepad.
InputSystem.RegisterLayout<XInputController>();
////FIXME: layouts should always be available in the editor (mac/win/linux)
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_WSA
InputSystem.RegisterLayout<XInputControllerWindows>(
matches: new InputDeviceMatcher().WithInterface("XInput"));
#endif
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
InputSystem.RegisterLayout<XboxGamepadMacOS>(
matches: new InputDeviceMatcher().WithInterface("HID")
.WithProduct("Xbox.*Wired Controller"));
// Matching older Xbox One controllers that have different View and Share buttons than the newer Xbox Series
// controllers.
// Reported inhttps://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1264
// Based on devices from this list
// https://github.com/mdqinc/SDL_GameControllerDB/blob/a453871de2e0e2484544514c6c080e1e916d620c/gamecontrollerdb.txt#L798C1-L806C1
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02B0);
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02D1);
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02DD);
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02E0);
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02E3);
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02EA);
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02FD);
RegisterXboxOneWirelessFromProductAndVendorID(0x045E, 0x02FF);
// This layout is for all the other Xbox One or Series controllers that have the same View and Share buttons.
// Reported in https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-385
InputSystem.RegisterLayout<XboxGamepadMacOSWireless>(
matches: new InputDeviceMatcher().WithInterface("HID")
.WithProduct("Xbox.*Wireless Controller"));
void RegisterXboxOneWirelessFromProductAndVendorID(int vendorId, int productId)
{
InputSystem.RegisterLayout<XboxOneGampadMacOSWireless>(
matches: new InputDeviceMatcher().WithInterface("HID")
.WithProduct("Xbox.*Wireless Controller")
.WithCapability("vendorId", vendorId)
.WithCapability("productId", productId));
}
#endif
}
}
}