This commit is contained in:
2025-01-17 13:10:42 +01:00
commit 4536213c91
15115 changed files with 1442174 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
using UnityEngine.InputSystem.Haptics;
namespace UnityEngine.InputSystem.XInput
{
/// <summary>
/// Extended dual motor gamepad rumble that adds left and right trigger motors.
/// </summary>
public interface IXboxOneRumble : IDualMotorRumble
{
void SetMotorSpeeds(float lowFrequency, float highFrequency, float leftTrigger, float rightTrigger);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3d2dbd5e535742a18f979fdaa69e3627
timeCreated: 1517012576

View File

@@ -0,0 +1,192 @@
using System;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
////TODO: expose user index
////TODO: set displayNames of the controls according to Xbox controller standards
namespace UnityEngine.InputSystem.XInput
{
/// <summary>
/// An XInput-compatible game controller.
/// </summary>
/// <remarks>
/// Note that on non-Microsoft platforms, XInput controllers will not actually use the XInput interface
/// but will rather be interfaced with through different APIs -- on OSX, for example, HID is used to
/// interface with Xbox controlllers. In those cases, XInput-specific functionality (like <see cref="Capabilities"/>)
/// will not be available.
///
/// On Windows, XInput controllers will be reported with <see cref="InputDeviceDescription.interfaceName"/>
/// set to <c>"XInput"</c> and with a JSON representation of <a
/// href="https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_capabilities">XINPUT_CAPABILITIES</a>
/// available in <see cref="InputDeviceDescription.capabilities"/>. This means that you match on those
/// <c>subType</c> and/or <c>flags</c> for example.
///
/// <example>
/// <code>
/// // Create an XInput-specific guitar layout subtype.
/// // NOTE: Works only on Windows.
/// InputSystem.RegisterLayout(@"
/// {
/// ""name"" : ""XInputGuitar"",
/// ""displayName"" : ""Guitar"",
/// ""extend"" : ""XInputController"",
/// ""device"" : {
/// ""interface"" : ""XInput"",
/// ""capabilities"" : [
/// { ""path"" : ""subType"", ""value"" : ""6"" }
/// ]
/// }
/// }
/// ");
/// </code>
/// </example>
///
/// Now, when an XInput controller is connected and reports itself with the
/// subtype "Guitar", it is turned into an "XInputGuitar" instead of an
/// "XInputController".
/// </remarks>
[InputControlLayout(displayName = "Xbox Controller")]
public class XInputController : Gamepad
{
/// <summary>
/// Same as <see cref="Gamepad.startButton"/>.
/// </summary>
/// <value>Same control as <see cref="Gamepad.startButton"/>.</value>
// Change the display names for the buttons to conform to Xbox conventions.
[InputControl(name = "buttonSouth", displayName = "A")]
[InputControl(name = "buttonEast", displayName = "B")]
[InputControl(name = "buttonWest", displayName = "X")]
[InputControl(name = "buttonNorth", displayName = "Y")]
[InputControl(name = "leftShoulder", displayName = "Left Bumper", shortDisplayName = "LB")]
[InputControl(name = "rightShoulder", displayName = "Right Bumper", shortDisplayName = "RB")]
[InputControl(name = "leftTrigger", shortDisplayName = "LT")]
[InputControl(name = "rightTrigger", shortDisplayName = "RT")]
// This follows Xbox One conventions; on Xbox 360, this is start=start and select=back.
[InputControl(name = "start", displayName = "Menu", alias = "menu")]
[InputControl(name = "select", displayName = "View", alias = "view")]
public ButtonControl menu { get; protected set; }
/// <summary>
/// Same as <see cref="Gamepad.selectButton"/>
/// </summary>
/// <value>Same control as <see cref="Gamepad.selectButton"/>.</value>
public ButtonControl view { get; protected set; }
/// <summary>
/// What specific kind of XInput controller this is.
/// </summary>
/// <value>XInput device subtype.</value>
/// <remarks>
/// When the controller is picked up through interfaces other than XInput or through old versions of
/// XInput, this will always be <see cref="DeviceSubType.Unknown"/>. Put another way, this value is
/// meaningful only on recent Microsoft platforms.
/// </remarks>
/// <seealso href="https://docs.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes"/>
public DeviceSubType subType
{
get
{
if (!m_HaveParsedCapabilities)
ParseCapabilities();
return m_SubType;
}
}
/// <summary>
/// Return the device flags as reported by XInput.
/// </summary>
/// <value>XInput device flags.</value>
/// <seealso href="https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_capabilities"/>
public DeviceFlags flags
{
get
{
if (!m_HaveParsedCapabilities)
ParseCapabilities();
return m_Flags;
}
}
/// <inheritdoc />
protected override void FinishSetup()
{
base.FinishSetup();
menu = startButton;
view = selectButton;
}
private bool m_HaveParsedCapabilities;
private DeviceSubType m_SubType;
private DeviceFlags m_Flags;
private void ParseCapabilities()
{
if (!string.IsNullOrEmpty(description.capabilities))
{
var capabilities = JsonUtility.FromJson<Capabilities>(description.capabilities);
m_SubType = capabilities.subType;
m_Flags = capabilities.flags;
}
m_HaveParsedCapabilities = true;
}
/// <summary>
/// Controller type enumeration in <c>Type</c> field of <c>XINPUT_CAPABILITIES</c>.
/// </summary>
/// <remarks>
/// See <a href="https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_capabilities">MSDN</a>.
/// </remarks>
internal enum DeviceType
{
Gamepad = 0x00
}
/// <summary>
/// Controller subtype enumeration in <c>SubType</c> field of <c>XINPUT_CAPABILITIES</c>.
/// </summary>
/// <remarks>
/// See <a href="https://docs.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes">MSDN</a>.
/// </remarks>
public enum DeviceSubType
{
Unknown = 0x00,
Gamepad = 0x01,
Wheel = 0x02,
ArcadeStick = 0x03,
FlightStick = 0x04,
DancePad = 0x05,
Guitar = 0x06,
GuitarAlternate = 0x07,
DrumKit = 0x08,
GuitarBass = 0x0B,
ArcadePad = 0x13
}
/// <summary>
/// Controller flags in <c>Flags</c> field of <c>XINPUT_CAPABILITIES</c>.
/// </summary>
/// <remarks>
/// See <a href="https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_capabilities">MSDN</a>.
/// </remarks>
[Flags]
public new enum DeviceFlags
{
ForceFeedbackSupported = 0x01,
Wireless = 0x02,
VoiceSupported = 0x04,
PluginModulesSupported = 0x08,
NoNavigation = 0x10,
}
[Serializable]
internal struct Capabilities
{
public DeviceType type;
public DeviceSubType subType;
public DeviceFlags flags;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7ae2dc3fc1c44ea59667819ea1d2e0c5
timeCreated: 1513463633

View File

@@ -0,0 +1,99 @@
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_WSA
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.XInput.LowLevel;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Scripting;
namespace UnityEngine.InputSystem.XInput.LowLevel
{
// IMPORTANT: State layout is XINPUT_GAMEPAD
[StructLayout(LayoutKind.Explicit, Size = 4)]
internal struct XInputControllerWindowsState : IInputStateTypeInfo
{
public FourCC format => new FourCC('X', 'I', 'N', 'P');
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "False positive")]
public enum Button
{
DPadUp = 0,
DPadDown = 1,
DPadLeft = 2,
DPadRight = 3,
Start = 4,
Select = 5,
LeftThumbstickPress = 6,
RightThumbstickPress = 7,
LeftShoulder = 8,
RightShoulder = 9,
A = 12,
B = 13,
X = 14,
Y = 15,
}
[InputControl(name = "dpad", layout = "Dpad", sizeInBits = 4, bit = 0)]
[InputControl(name = "dpad/up", bit = (uint)Button.DPadUp)]
[InputControl(name = "dpad/down", bit = (uint)Button.DPadDown)]
[InputControl(name = "dpad/left", bit = (uint)Button.DPadLeft)]
[InputControl(name = "dpad/right", bit = (uint)Button.DPadRight)]
[InputControl(name = "start", bit = (uint)Button.Start, displayName = "Start")]
[InputControl(name = "select", bit = (uint)Button.Select, displayName = "Select")]
[InputControl(name = "leftStickPress", bit = (uint)Button.LeftThumbstickPress)]
[InputControl(name = "rightStickPress", bit = (uint)Button.RightThumbstickPress)]
[InputControl(name = "leftShoulder", bit = (uint)Button.LeftShoulder)]
[InputControl(name = "rightShoulder", bit = (uint)Button.RightShoulder)]
[InputControl(name = "buttonSouth", bit = (uint)Button.A, displayName = "A")]
[InputControl(name = "buttonEast", bit = (uint)Button.B, displayName = "B")]
[InputControl(name = "buttonWest", bit = (uint)Button.X, displayName = "X")]
[InputControl(name = "buttonNorth", bit = (uint)Button.Y, displayName = "Y")]
[FieldOffset(0)]
public ushort buttons;
[InputControl(name = "leftTrigger", format = "BYTE")]
[FieldOffset(2)] public byte leftTrigger;
[InputControl(name = "rightTrigger", format = "BYTE")]
[FieldOffset(3)] public byte rightTrigger;
[InputControl(name = "leftStick", layout = "Stick", format = "VC2S")]
[InputControl(name = "leftStick/x", offset = 0, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
[InputControl(name = "leftStick/left", offset = 0, format = "SHRT")]
[InputControl(name = "leftStick/right", offset = 0, format = "SHRT")]
[InputControl(name = "leftStick/y", offset = 2, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
[InputControl(name = "leftStick/up", offset = 2, format = "SHRT")]
[InputControl(name = "leftStick/down", offset = 2, format = "SHRT")]
[FieldOffset(4)] public short leftStickX;
[FieldOffset(6)] public short leftStickY;
[InputControl(name = "rightStick", layout = "Stick", format = "VC2S")]
[InputControl(name = "rightStick/x", offset = 0, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
[InputControl(name = "rightStick/left", offset = 0, format = "SHRT")]
[InputControl(name = "rightStick/right", offset = 0, format = "SHRT")]
[InputControl(name = "rightStick/y", offset = 2, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
[InputControl(name = "rightStick/up", offset = 2, format = "SHRT")]
[InputControl(name = "rightStick/down", offset = 2, format = "SHRT")]
[FieldOffset(8)] public short rightStickX;
[FieldOffset(10)] public short rightStickY;
public XInputControllerWindowsState WithButton(Button button)
{
Debug.Assert((int)button < 16, $"Expected button < 16, so we fit into the 16 bit wide bitmask");
buttons |= (ushort)(1U << (int)button);
return this;
}
}
}
namespace UnityEngine.InputSystem.XInput
{
/// <summary>
/// An <see cref="XInputController"/> compatible game controller connected to a Windows desktop machine.
/// </summary>
[InputControlLayout(stateType = typeof(XInputControllerWindowsState), hideInUI = true)]
public class XInputControllerWindows : XInputController
{
}
}
#endif // UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_WSA

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a3e3635b85e2124b9b3147aef1cdc32
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@
////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"));
InputSystem.RegisterLayout<XboxOneGampadMacOSWireless>(
matches: new InputDeviceMatcher().WithInterface("HID")
.WithProduct("Xbox.*Wireless Controller"));
#endif
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0dd5cd31dc0a44e8979c69bd6ef78686
timeCreated: 1511134620

View File

@@ -0,0 +1,227 @@
#if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX || PACKAGE_DOCS_GENERATION
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Layouts;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.XInput.LowLevel;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Scripting;
namespace UnityEngine.InputSystem.XInput.LowLevel
{
// Xbox one controller on OSX. State layout can be found here:
// https://github.com/360Controller/360Controller/blob/master/360Controller/ControlStruct.h
// struct InputReport
// {
// byte command;
// byte size;
// short buttons;
// byte triggerLeft;
// byte triggerRight;
// short leftX;
// short leftY;
// short rightX;
// short rightY;
// }
// Report size is 14 bytes. First two bytes are header information for the report.
[StructLayout(LayoutKind.Explicit)]
internal struct XInputControllerOSXState : IInputStateTypeInfo
{
public static FourCC kFormat => new FourCC('H', 'I', 'D');
public enum Button
{
DPadUp = 0,
DPadDown = 1,
DPadLeft = 2,
DPadRight = 3,
Start = 4,
Select = 5,
LeftThumbstickPress = 6,
RightThumbstickPress = 7,
LeftShoulder = 8,
RightShoulder = 9,
A = 12,
B = 13,
X = 14,
Y = 15,
}
[FieldOffset(0)]
private ushort padding;
[InputControl(name = "dpad", layout = "Dpad", sizeInBits = 4, bit = 0)]
[InputControl(name = "dpad/up", bit = (uint)Button.DPadUp)]
[InputControl(name = "dpad/down", bit = (uint)Button.DPadDown)]
[InputControl(name = "dpad/left", bit = (uint)Button.DPadLeft)]
[InputControl(name = "dpad/right", bit = (uint)Button.DPadRight)]
[InputControl(name = "start", bit = (uint)Button.Start, displayName = "Start")]
[InputControl(name = "select", bit = (uint)Button.Select, displayName = "Select")]
[InputControl(name = "leftStickPress", bit = (uint)Button.LeftThumbstickPress)]
[InputControl(name = "rightStickPress", bit = (uint)Button.RightThumbstickPress)]
[InputControl(name = "leftShoulder", bit = (uint)Button.LeftShoulder)]
[InputControl(name = "rightShoulder", bit = (uint)Button.RightShoulder)]
[InputControl(name = "buttonSouth", bit = (uint)Button.A, displayName = "A")]
[InputControl(name = "buttonEast", bit = (uint)Button.B, displayName = "B")]
[InputControl(name = "buttonWest", bit = (uint)Button.X, displayName = "X")]
[InputControl(name = "buttonNorth", bit = (uint)Button.Y, displayName = "Y")]
[FieldOffset(2)]
public ushort buttons;
[InputControl(name = "leftTrigger", format = "BYTE")]
[FieldOffset(4)] public byte leftTrigger;
[InputControl(name = "rightTrigger", format = "BYTE")]
[FieldOffset(5)] public byte rightTrigger;
[InputControl(name = "leftStick", layout = "Stick", format = "VC2S")]
[InputControl(name = "leftStick/x", offset = 0, format = "SHRT", parameters = "")]
[InputControl(name = "leftStick/left", offset = 0, format = "SHRT", parameters = "")]
[InputControl(name = "leftStick/right", offset = 0, format = "SHRT", parameters = "")]
[InputControl(name = "leftStick/y", offset = 2, format = "SHRT", parameters = "invert")]
[InputControl(name = "leftStick/up", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert=true")]
[InputControl(name = "leftStick/down", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=0,clampMax=1,invert=false")]
[FieldOffset(6)] public short leftStickX;
[FieldOffset(8)] public short leftStickY;
[InputControl(name = "rightStick", layout = "Stick", format = "VC2S")]
[InputControl(name = "rightStick/x", offset = 0, format = "SHRT", parameters = "")]
[InputControl(name = "rightStick/left", offset = 0, format = "SHRT", parameters = "")]
[InputControl(name = "rightStick/right", offset = 0, format = "SHRT", parameters = "")]
[InputControl(name = "rightStick/y", offset = 2, format = "SHRT", parameters = "invert")]
[InputControl(name = "rightStick/up", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert=true")]
[InputControl(name = "rightStick/down", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=0,clampMax=1,invert=false")]
[FieldOffset(10)] public short rightStickX;
[FieldOffset(12)] public short rightStickY;
public FourCC format => kFormat;
public XInputControllerOSXState WithButton(Button button)
{
Debug.Assert((int)button < 16, $"Expected button < 16, so we fit into the 16 bit wide bitmask");
buttons |= (ushort)(1U << (int)button);
return this;
}
}
[StructLayout(LayoutKind.Explicit)]
internal struct XInputControllerWirelessOSXState : IInputStateTypeInfo
{
public static FourCC kFormat => new FourCC('H', 'I', 'D');
public enum Button
{
Start = 11,
Select = 10,
LeftThumbstickPress = 13,
RightThumbstickPress = 14,
LeftShoulder = 6,
RightShoulder = 7,
A = 0,
B = 1,
X = 3,
Y = 4,
}
[FieldOffset(0)]
private byte padding;
[InputControl(name = "leftStick", layout = "Stick", format = "VC2S")]
[InputControl(name = "leftStick/x", offset = 0, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[InputControl(name = "leftStick/left", offset = 0, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
[InputControl(name = "leftStick/right", offset = 0, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
[InputControl(name = "leftStick/y", offset = 2, format = "USHT", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[InputControl(name = "leftStick/up", offset = 2, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
[InputControl(name = "leftStick/down", offset = 2, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
[FieldOffset(1)] public ushort leftStickX;
[FieldOffset(3)] public ushort leftStickY;
[InputControl(name = "rightStick", layout = "Stick", format = "VC2S")]
[InputControl(name = "rightStick/x", offset = 0, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[InputControl(name = "rightStick/left", offset = 0, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
[InputControl(name = "rightStick/right", offset = 0, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1")]
[InputControl(name = "rightStick/y", offset = 2, format = "USHT", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
[InputControl(name = "rightStick/up", offset = 2, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0,clampMax=0.5,invert")]
[InputControl(name = "rightStick/down", offset = 2, format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp=1,clampMin=0.5,clampMax=1,invert=false")]
[FieldOffset(5)] public ushort rightStickX;
[FieldOffset(7)] public ushort rightStickY;
[InputControl(name = "leftTrigger", format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=0.01560998")]
[FieldOffset(9)] public ushort leftTrigger;
[InputControl(name = "rightTrigger", format = "USHT", parameters = "normalize,normalizeMin=0,normalizeMax=0.01560998")]
[FieldOffset(11)] public ushort rightTrigger;
[InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
[InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=8,maxValue=2,nullValue=0,wrapAtValue=9", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=2,maxValue=4", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=4,maxValue=6", bit = 0, sizeInBits = 4)]
[InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=6, maxValue=8", bit = 0, sizeInBits = 4)]
[FieldOffset(13)]
public byte dpad;
[InputControl(name = "start", bit = (uint)Button.Start, displayName = "Start")]
[InputControl(name = "select", bit = (uint)Button.Select, displayName = "Select")]
[InputControl(name = "leftStickPress", bit = (uint)Button.LeftThumbstickPress)]
[InputControl(name = "rightStickPress", bit = (uint)Button.RightThumbstickPress)]
[InputControl(name = "leftShoulder", bit = (uint)Button.LeftShoulder)]
[InputControl(name = "rightShoulder", bit = (uint)Button.RightShoulder)]
[InputControl(name = "buttonSouth", bit = (uint)Button.A, displayName = "A")]
[InputControl(name = "buttonEast", bit = (uint)Button.B, displayName = "B")]
[InputControl(name = "buttonWest", bit = (uint)Button.X, displayName = "X")]
[InputControl(name = "buttonNorth", bit = (uint)Button.Y, displayName = "Y")]
[FieldOffset(14)]
public uint buttons;
public FourCC format => kFormat;
public XInputControllerWirelessOSXState WithButton(Button button)
{
Debug.Assert((int)button < 32, $"Expected button < 32, so we fit into the 32 bit wide bitmask");
buttons |= 1U << (int)button;
return this;
}
public XInputControllerWirelessOSXState WithDpad(byte value)
{
dpad = value;
return this;
}
public static XInputControllerWirelessOSXState defaultState => new XInputControllerWirelessOSXState
{
rightStickX = 32767,
rightStickY = 32767,
leftStickX = 32767,
leftStickY = 32767
};
}
}
namespace UnityEngine.InputSystem.XInput
{
/// <summary>
/// A wired Xbox Gamepad connected to a macOS computer.
/// </summary>
/// <remarks>
/// An Xbox 360 or Xbox one wired gamepad connected to a mac.
/// These controllers don't work on a mac out of the box, but require a driver like https://github.com/360Controller/
/// to work.
/// </remarks>
[InputControlLayout(displayName = "Xbox Controller", stateType = typeof(XInputControllerOSXState), hideInUI = true)]
public class XboxGamepadMacOS : XInputController
{
}
/// <summary>
/// A wireless Xbox One Gamepad connected to a macOS computer.
/// </summary>
/// <remarks>
/// An Xbox One wireless gamepad connected to a mac using Bluetooth.
/// Note: only the latest version of Xbox One wireless gamepads support Bluetooth. Older models only work
/// with a proprietary Xbox wireless protocol, and cannot be used on a Mac.
/// Unlike wired controllers, bluetooth-cabable Xbox One controllers do not need a custom driver to work on macOS.
/// </remarks>
[InputControlLayout(displayName = "Wireless Xbox Controller", stateType = typeof(XInputControllerWirelessOSXState), hideInUI = true)]
public class XboxOneGampadMacOSWireless : XInputController
{
}
}
#endif // UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ef73fbf6f536c4184845d789870911a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: