UI 자동화를 위해 바인딩 기능 구현
- 유니티 에셋 인증 오류로 meta 재생성
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d2dbd5e535742a18f979fdaa69e3627
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,328 @@
|
||||
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>
|
||||
/// Provides additional detail about the underlying hardware being used and how it maps physical to logical
|
||||
/// controls.
|
||||
///
|
||||
/// See <a href="https://docs.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes">MSDN</a>
|
||||
/// for additional details.
|
||||
/// </remarks>
|
||||
public enum DeviceSubType
|
||||
{
|
||||
/// <summary>
|
||||
/// The controller type is unknown.
|
||||
/// </summary>
|
||||
Unknown = 0x00,
|
||||
|
||||
/// <summary>
|
||||
/// Gamepad controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Includes left and right stick as <see cref="Gamepad.leftStick" /> and <see cref="Gamepad.rightStick"/>,
|
||||
/// left and right trigger as <see cref="Gamepad.leftTrigger"/> and <see cref="Gamepad.rightTrigger"/>,
|
||||
/// directional pad as <see cref="Gamepad.dpad"/>,
|
||||
/// and all standard buttons (<see cref="Gamepad.buttonSouth"/>, <see cref="Gamepad.buttonEast"/>,
|
||||
/// <see cref="Gamepad.buttonWest"/>, <see cref="Gamepad.buttonNorth"/>,
|
||||
/// <see cref="Gamepad.startButton"/>, <see cref="Gamepad.selectButton"/>,
|
||||
/// <see cref="Gamepad.leftShoulder"/>, <see cref="Gamepad.rightShoulder"/>,
|
||||
/// <see cref="Gamepad.leftStickButton"/>, <see cref="Gamepad.rightStickButton"/>).
|
||||
/// </remarks>
|
||||
Gamepad = 0x01,
|
||||
|
||||
/// <summary>
|
||||
/// Racing wheel controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="UnityEngine.InputSystem.Gamepad.leftStick" /> x-axis reports the wheel rotation,
|
||||
/// <see cref="Gamepad.rightTrigger"/> is the acceleration pedal, and
|
||||
/// <see cref="Gamepad.leftTrigger"/>Left Trigger is the brake pedal.
|
||||
/// Includes Directional Pad as <see cref="Gamepad.dpad"/> and most standard buttons
|
||||
/// (<see cref="Gamepad.buttonSouth"/>, <see cref="Gamepad.buttonEast"/>,
|
||||
/// <see cref="Gamepad.buttonWest"/>, <see cref="Gamepad.buttonNorth"/>,
|
||||
/// <see cref="Gamepad.startButton"/>, <see cref="Gamepad.selectButton"/>,
|
||||
/// <see cref="Gamepad.leftShoulder"/>, <see cref="Gamepad.rightShoulder"/>).
|
||||
/// <see cref="Gamepad.leftStickButton"/> and <see cref="Gamepad.rightStickButton"/> are optional.
|
||||
/// </remarks>
|
||||
Wheel = 0x02,
|
||||
|
||||
/// <summary>
|
||||
/// Arcade stick controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Includes a Digital Stick that reports as a <see cref="Gamepad.dpad"/> (up, down, left, right),
|
||||
/// and most standard buttons (<see cref="Gamepad.buttonSouth"/>, <see cref="Gamepad.buttonEast"/>,
|
||||
/// <see cref="Gamepad.buttonWest"/>, <see cref="Gamepad.buttonNorth"/>,
|
||||
/// <see cref="Gamepad.startButton"/>, <see cref="Gamepad.selectButton"/>).
|
||||
/// The <see cref="Gamepad.leftTrigger"/> and <see cref="Gamepad.rightTrigger"/> are implemented as digital
|
||||
/// buttons and report either 0.0f or 1.0f.
|
||||
/// The <see cref="Gamepad.leftShoulder"/>, <see cref="Gamepad.rightShoulder"/> and
|
||||
/// <see cref="Gamepad.leftStickButton"/>, <see cref="Gamepad.rightStickButton"/> are optional.
|
||||
/// </remarks>
|
||||
ArcadeStick = 0x03,
|
||||
|
||||
/// <summary>
|
||||
/// Flight stick controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Includes a pitch and roll stick that reports as the <see cref="Gamepad.leftStick"/>, a POV Hat which
|
||||
/// reports as the <see cref="Gamepad.rightStick"/>, a rudder (handle twist or rocker) that reports as
|
||||
/// <see cref="Gamepad.leftTrigger"/>, and a throttle control as the <see cref="Gamepad.rightTrigger"/>.
|
||||
/// Includes support for a primary weapon (<see cref="Gamepad.buttonSouth"/>), secondary weapon
|
||||
/// (<see cref="Gamepad.buttonEast"/>), and other standard buttons (<see cref="Gamepad.buttonWest"/>,
|
||||
/// <see cref="Gamepad.buttonNorth"/>, <see cref="Gamepad.startButton"/>,
|
||||
/// <see cref="Gamepad.selectButton"/>).
|
||||
/// <see cref="Gamepad.leftShoulder"/>, <see cref="Gamepad.rightShoulder"/> and
|
||||
/// <see cref="Gamepad.leftStickButton"/>, <see cref="Gamepad.rightStickButton"/> are optional.
|
||||
/// </remarks>
|
||||
FlightStick = 0x04,
|
||||
|
||||
/// <summary>
|
||||
/// Dance pad controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Includes the <see cref="Gamepad.dpad"/> and standard buttons (<see cref="Gamepad.buttonSouth"/>,
|
||||
/// <see cref="Gamepad.buttonEast"/>, <see cref="Gamepad.buttonWest"/>,
|
||||
/// <see cref="Gamepad.buttonNorth"/>) on the pad, plus <see cref="Gamepad.startButton"/> and
|
||||
/// <see cref="Gamepad.selectButton"/>.
|
||||
/// </remarks>
|
||||
DancePad = 0x05,
|
||||
|
||||
/// <summary>
|
||||
/// Guitar controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The strum bar maps to <see cref="Gamepad.dpad"/> (up and down), and the frets are assigned to
|
||||
/// <see cref="Gamepad.buttonSouth"/> (green), <see cref="Gamepad.buttonEast"/> (red),
|
||||
/// <see cref="Gamepad.buttonNorth"/> (yellow), <see cref="Gamepad.buttonWest"/> (blue), and
|
||||
/// <see cref="Gamepad.leftShoulder"/> (orange).
|
||||
/// <see cref="Gamepad.rightStick"/> y-axis is associated with a vertical orientation sensor;
|
||||
/// <see cref="Gamepad.rightStick"/> x-axis is the whammy bar.
|
||||
/// Includes support for <see cref="Gamepad.selectButton"/>, <see cref="Gamepad.startButton"/>,
|
||||
/// <see cref="Gamepad.dpad"/> (left, right).
|
||||
/// <see cref="Gamepad.leftTrigger"/> (pickup selector), <see cref="Gamepad.rightTrigger"/>,
|
||||
/// <see cref="Gamepad.rightShoulder"/>, <see cref="Gamepad.leftStickButton"/> (fret modifier),
|
||||
/// <see cref="Gamepad.rightStickButton"/> are optional.
|
||||
/// </remarks>
|
||||
Guitar = 0x06,
|
||||
|
||||
/// <summary>
|
||||
/// Alternate guitar controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Similar to <see cref="Guitar"/> but supports a larger range of movement for the vertical orientation
|
||||
/// sensor.
|
||||
/// </remarks>
|
||||
GuitarAlternate = 0x07,
|
||||
|
||||
/// <summary>
|
||||
/// Drum kit controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The drum pads are assigned to buttons: <see cref="Gamepad.buttonSouth"/> for green (Floor Tom),
|
||||
/// <see cref="Gamepad.buttonEast"/> for red (Snare Drum),
|
||||
/// <see cref="Gamepad.buttonWest"/> for blue (Low Tom),
|
||||
/// <see cref="Gamepad.buttonNorth"/> for yellow (High Tom),
|
||||
/// and <see cref="Gamepad.leftShoulder"/> for the pedal (Bass Drum).
|
||||
/// Includes <see cref="Gamepad.dpad"/>, <see cref="Gamepad.selectButton"/>, and
|
||||
/// <see cref="Gamepad.startButton"/>. <see cref="Gamepad.rightShoulder"/>,
|
||||
/// <see cref="Gamepad.leftStickButton"/>, and <see cref="Gamepad.rightStickButton"/> are optional.
|
||||
/// </remarks>
|
||||
DrumKit = 0x08,
|
||||
|
||||
/// <summary>
|
||||
/// Bass guitar controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Identical to <see cref="Guitar" />, with the distinct subtype to simplify setup.
|
||||
/// </remarks>
|
||||
GuitarBass = 0x0B,
|
||||
|
||||
/// <summary>
|
||||
/// Arcade pad controller.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Includes Directional Pad and most standard buttons
|
||||
/// (<see cref="Gamepad.buttonSouth"/>, <see cref="Gamepad.buttonEast"/>,
|
||||
/// <see cref="Gamepad.buttonWest"/>, <see cref="Gamepad.buttonNorth"/>,
|
||||
/// <see cref="Gamepad.startButton"/>, <see cref="Gamepad.selectButton"/>,
|
||||
/// <see cref="Gamepad.leftShoulder"/>, <see cref="Gamepad.rightShoulder"/>).
|
||||
/// The <see cref="Gamepad.leftTrigger"/>, <see cref="Gamepad.rightTrigger"/> are implemented as digital
|
||||
/// buttons and report either 0.0f or 1.0f.
|
||||
/// <see cref="Gamepad.leftStick"/>, <see cref="Gamepad.rightStick"/>,
|
||||
/// <see cref="Gamepad.leftStickButton"/> and <see cref="Gamepad.rightStickButton"/> are optional.
|
||||
/// </remarks>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ae2dc3fc1c44ea59667819ea1d2e0c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a3e3635b85e2124b9b3147aef1cdc32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,72 @@
|
||||
////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
|
||||
// Legacy support when a user is using the 360Controller driver on macOS <= 10.15
|
||||
InputSystem.RegisterLayout<XboxGamepadMacOS>(
|
||||
matches: new InputDeviceMatcher().WithInterface("HID")
|
||||
.WithProduct("Xbox.*Wired Controller"));
|
||||
|
||||
|
||||
// Matches macOS native support for Xbox Controllers
|
||||
// macOS reports all Xbox controllers as "Controller" with manufacter Microsoft
|
||||
InputSystem.RegisterLayout<XboxGamepadMacOSNative>(
|
||||
matches: new InputDeviceMatcher().WithInterface("HID")
|
||||
.WithProduct("Controller").WithManufacturer("Microsoft"));
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0dd5cd31dc0a44e8979c69bd6ef78686
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,433 @@
|
||||
#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, $"A maximum of 16 buttons is supported for this layout.");
|
||||
buttons |= (ushort)(1U << (int)button);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// macOS's native bit mapping for Xbox Controllers connected via USB
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct XInputControllerNativeOSXState : IInputStateTypeInfo
|
||||
{
|
||||
public static FourCC kFormat => new FourCC('H', 'I', 'D');
|
||||
|
||||
public enum Button
|
||||
{
|
||||
Start = 2,
|
||||
Select = 3,
|
||||
A = 4,
|
||||
B = 5,
|
||||
X = 6,
|
||||
Y = 7,
|
||||
DPadUp = 8,
|
||||
DPadDown = 9,
|
||||
DPadLeft = 10,
|
||||
DPadRight = 11,
|
||||
LeftShoulder = 12,
|
||||
RightShoulder = 13,
|
||||
LeftThumbstickPress = 14,
|
||||
RightThumbstickPress = 15,
|
||||
}
|
||||
|
||||
[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")]
|
||||
[InputControl(name = "start", bit = (uint)Button.Start, displayName = "Start")]
|
||||
[InputControl(name = "select", bit = (uint)Button.Select, displayName = "Select")]
|
||||
[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 = "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)]
|
||||
[FieldOffset(4)]
|
||||
public ushort buttons;
|
||||
|
||||
[InputControl(name = "leftTrigger", format = "BYTE")]
|
||||
[FieldOffset(6)] public byte leftTrigger;
|
||||
|
||||
[InputControl(name = "rightTrigger", format = "BYTE")]
|
||||
[FieldOffset(8)] 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 = "")]
|
||||
[InputControl(name = "leftStick/up", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=0,clampMax=1,invert=false")]
|
||||
[InputControl(name = "leftStick/down", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert=true")]
|
||||
[FieldOffset(10)] public short leftStickX;
|
||||
[FieldOffset(12)] 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 = "")]
|
||||
[InputControl(name = "rightStick/up", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=0,clampMax=1,invert=false")]
|
||||
[InputControl(name = "rightStick/down", offset = 2, format = "SHRT", parameters = "clamp=1,clampMin=-1,clampMax=0,invert=true")]
|
||||
[FieldOffset(14)] public short rightStickX;
|
||||
[FieldOffset(16)] public short rightStickY;
|
||||
|
||||
public FourCC format => kFormat;
|
||||
|
||||
public XInputControllerNativeOSXState WithButton(Button button)
|
||||
{
|
||||
Debug.Assert((int)button < 16, $"A maximum of 16 buttons is supported for this layout.");
|
||||
buttons |= (ushort)(1U << (int)button);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct XInputControllerWirelessOSXState : IInputStateTypeInfo
|
||||
{
|
||||
const ushort k_StickZeroValue = 32767;
|
||||
public static FourCC kFormat => new FourCC('H', 'I', 'D');
|
||||
|
||||
public enum Button
|
||||
{
|
||||
Start = 11,
|
||||
Select = 16,
|
||||
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", defaultState = k_StickZeroValue)]
|
||||
[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", defaultState = k_StickZeroValue)]
|
||||
[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", defaultState = k_StickZeroValue)]
|
||||
[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", defaultState = k_StickZeroValue)]
|
||||
[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)]
|
||||
[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, $"A maximum of 32 buttons is supported for this layout.");
|
||||
buttons |= 1U << (int)button;
|
||||
return this;
|
||||
}
|
||||
|
||||
public XInputControllerWirelessOSXState WithDpad(byte value)
|
||||
{
|
||||
dpad = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static XInputControllerWirelessOSXState defaultState => new XInputControllerWirelessOSXState
|
||||
{
|
||||
rightStickX = k_StickZeroValue,
|
||||
rightStickY = k_StickZeroValue,
|
||||
leftStickX = k_StickZeroValue,
|
||||
leftStickY = k_StickZeroValue
|
||||
};
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
internal struct XInputControllerWirelessOSXStateV2 : IInputStateTypeInfo
|
||||
{
|
||||
const ushort k_StickZeroValue = 32767;
|
||||
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", defaultState = k_StickZeroValue)]
|
||||
[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", defaultState = k_StickZeroValue)]
|
||||
[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", defaultState = k_StickZeroValue)]
|
||||
[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", defaultState = k_StickZeroValue)]
|
||||
[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)]
|
||||
[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 XInputControllerWirelessOSXStateV2 WithButton(Button button)
|
||||
{
|
||||
Debug.Assert((int)button < 32, $"A maximum of 32 buttons is supported for this layout.");
|
||||
buttons |= 1U << (int)button;
|
||||
return this;
|
||||
}
|
||||
|
||||
public XInputControllerWirelessOSXStateV2 WithDpad(byte value)
|
||||
{
|
||||
dpad = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static XInputControllerWirelessOSXStateV2 defaultState => new XInputControllerWirelessOSXStateV2
|
||||
{
|
||||
rightStickX = k_StickZeroValue,
|
||||
rightStickY = k_StickZeroValue,
|
||||
leftStickX = k_StickZeroValue,
|
||||
leftStickY = k_StickZeroValue
|
||||
};
|
||||
}
|
||||
}
|
||||
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.
|
||||
/// This layout is used for macOS versions when https://github.com/360Controller/ was required
|
||||
/// On modern macOS versions, you will instead get a device with class XboxGamepadMacOSNative
|
||||
/// </remarks>
|
||||
[InputControlLayout(displayName = "Xbox Controller", stateType = typeof(XInputControllerOSXState), hideInUI = true)]
|
||||
public class XboxGamepadMacOS : XInputController
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A wired Xbox Gamepad connected to a macOS computer
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An Xbox 360 or Xbox One wired gamepad connected ot a Mac.
|
||||
/// This layout is used on modern macOS systems. It is different from <see cref="XboxGamepadMacOS"/>, due to that working with older
|
||||
/// systems that are using the 360Controller driver.
|
||||
/// macOS's native controller support provides a bit mapping which is different to 360Controller's mapping
|
||||
/// As such this is a new device, in order to not break existing projects.
|
||||
/// </remarks>
|
||||
[InputControlLayout(displayName = "Xbox Controller", stateType = typeof(XInputControllerNativeOSXState), hideInUI = true)]
|
||||
public class XboxGamepadMacOSNative : 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-capable Xbox One controllers do not need a custom driver to work on older macOS versions
|
||||
/// </remarks>
|
||||
[InputControlLayout(displayName = "Wireless Xbox Controller", stateType = typeof(XInputControllerWirelessOSXState), hideInUI = true)]
|
||||
public class XboxOneGampadMacOSWireless : XInputController
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A wireless Xbox One or Xbox Series Gamepad connected to a macOS computer.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An Xbox One/Series wireless gamepad connected to a mac using Bluetooth.
|
||||
/// The reason this is different from <see cref="XboxOneGampadMacOSWireless"/> is that some Xbox Controllers have
|
||||
/// different View and Share button bit mapping. So we need to use a different layout for those controllers. It seems
|
||||
/// that some Xbox One and Xbox Series controller share the same mappings so this combines them all.
|
||||
/// > [!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 older macOS versions
|
||||
/// </remarks>
|
||||
[InputControlLayout(displayName = "Wireless Xbox Controller", stateType = typeof(XInputControllerWirelessOSXStateV2), hideInUI = true)]
|
||||
public class XboxGamepadMacOSWireless : XInputController
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif // UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef73fbf6f536c4184845d789870911a3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user