Skip to content

Commit 1ef7946

Browse files
authored
NEW: iOS gamepads support (#890)
1 parent 6e00488 commit 1ef7946

File tree

8 files changed

+54
-10
lines changed

8 files changed

+54
-10
lines changed

Assets/Tests/InputSystem/APIVerificationTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ bool IgnoreTypeForDocs(TypeDefinition type)
371371
type.FullName == typeof(UnityEngine.InputSystem.Steam.SteamHandle<>).FullName ||
372372
type.FullName == typeof(UnityEngine.InputSystem.Steam.Editor.SteamIGAConverter).FullName ||
373373
#endif
374-
type.FullName == typeof(UnityEngine.InputSystem.iOS.iOSGameController).FullName ||
375374
type.FullName == typeof(UnityEngine.InputSystem.DualShock.DualShock3GamepadHID).FullName ||
376375
type.FullName == typeof(UnityEngine.InputSystem.DualShock.DualShock4GamepadHID).FullName ||
377376
type.FullName == typeof(UnityEngine.InputSystem.Android.AndroidAccelerometer).FullName ||

ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/XboxISX.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ void Start()
1414
{
1515
//m_stickMaxMove = 0.25f;
1616

17-
m_buttonAction = new InputAction(name: "XboxButtonAction", InputActionType.PassThrough, binding: "XInputController*/<button>");
17+
m_buttonAction = new InputAction(name: "XboxButtonAction", InputActionType.PassThrough, binding: "<XInputController>/<button>");
1818
m_buttonAction.performed += callbackContext => OnControllerButtonPress(callbackContext.control as ButtonControl, isXbox: true);
1919
m_buttonAction.Enable();
2020

21-
m_dPadAction = new InputAction(name: "XboxDpadAction", InputActionType.PassThrough, binding: "XInputController*/<dpad>");
21+
m_dPadAction = new InputAction(name: "XboxDpadAction", InputActionType.PassThrough, binding: "<XInputController>/<dpad>");
2222
m_dPadAction.performed += callbackContext => OnDpadPress(callbackContext.control as DpadControl);
2323
m_dPadAction.Enable();
2424

2525
m_stickMoveAction = new InputAction(name: "XboxStickMoveAction", InputActionType.PassThrough,
26-
binding: "XInputController*/<stick>");
26+
binding: "<XInputController>/<stick>");
2727
m_stickMoveAction.performed += callbackContext => StickMove(callbackContext.control as StickControl);
2828
m_stickMoveAction.Enable();
2929
}

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ however, it has to be formatted properly to pass verification tests.
3030

3131
### Added
3232

33+
- Will now recognize Xbox One and PS4 controllers connected to iOS devices correctly as Xbox One and PS4 controllers.
3334
- Added a new sample called "Custom Device Usages" that shows how to use a layout override on `Gamepad` to allow distinguishing two gamepads in bindings based on which player the gamepad is assigned to.
3435

3536
## [1.0.0-preview] - 2019-9-20

Packages/com.unity.inputsystem/Documentation~/Gamepad.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ PlayStation controllers are well supported on different Devices. The Input Syste
101101

102102
* [`DualShock4GamepadHID`](../api/UnityEngine.InputSystem.DualShock.DualShock4GamepadHID.html): A DualShock 4 controller connected to a desktop computer using the HID interface. Supported on macOS, Windows, UWP, and Linux.
103103

104+
*
105+
[`DualShock4GampadiOS`](../api/UnityEngine.InputSystem.iOS.DualShock4GampadiOS.html): A DualShock 4 controller connected to an iOS Device via Bluetooth. Requires iOS 13 or higher.
106+
104107
[`DualShock4GamepadHID`](../api/UnityEngine.InputSystem.DualShock.DualShock4GamepadHID.html) implements additional, DualShock-specific functionality on top the general support in the [`Gamepad`](../api/UnityEngine.InputSystem.Gamepad.html) class:
105108

106109
* [`SetLightBarColor(Color)`](../api/UnityEngine.InputSystem.DualShock.DualShockGamepad.html#UnityEngine_InputSystem_DualShock_DualShockGamepad_SetLightBarColor_Color_): Lets you set the color of the light bar on the controller.
@@ -119,6 +122,9 @@ On other platforms Unity uses derived classes to represent Xbox controllers:
119122

120123
* [`XboxOneGampadMacOSWireless`](../api/UnityEngine.InputSystem.XInput.XboxOneGampadMacOSWireless.html): An Xbox One controller connected to a Mac via Bluetooth. Only the latest generation of Xbox One controllers supports Bluetooth. These controllers don't require any additional drivers in this scenario.
121124

125+
*
126+
[`XboxOneGampadiOS`](../api/UnityEngine.InputSystem.iOS.XboxOneGampadiOS.html): An Xbox One controller connected to an iOS Device via Bluetooth. Requires iOS 13 or higher.
127+
122128
>__Note__:
123129
>* XInput controllers on Mac currently require the installation of the [Xbox Controller Driver for macOS](https://github.com/360Controller/360Controller). Only USB connections are supported by this driver, no wireless dongles. However, the latest generation of Xbox One controllers natively supported Bluetooth. Macs natively support these controllers as HIDs without any additional drivers when connected via Bluetooth.
124130
>* Unity supports Xbox controllers on WebGL in some browser and OS configurations, but treats them as basic [`Gamepad`](../api/UnityEngine.InputSystem.Gamepad.html) or [`Joystick`](../api/UnityEngine.InputSystem.Joystick.html) Devices, and doesn't support Rumble or any other Xbox-specific functionality.

Packages/com.unity.inputsystem/Documentation~/SupportedDevices.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ The following Devices are supported in a way that doesn't require specialized su
2525
|Device|Windows|Mac|Linux|UWP|Android|iOS(6)|Xbox(7)|PS4(7)|Switch(7)|WebGL|
2626
|------|-------|---|-----|---|-------|---|----|---|------|-----|
2727
|Xbox 360 (4)|Yes|Yes (3)|Yes|Yes|No|No|Yes|No|No|Sometimes (2)|
28-
|Xbox One|Yes (1)|Yes (3)|Yes (1)|Yes|Yes (1)|No|Yes|No|No|Sometimes (2)|
29-
|PS4|Yes (5)|Yes (5)|Yes (5)|Yes (5)|Yes (5)|No|No|Yes|No|Sometimes (2)|
28+
|Xbox One|Yes (1)|Yes (3)|Yes (1)|Yes|Yes (1)|Yes (6)|Yes|No|No|Sometimes (2)|
29+
|PS4|Yes (5)|Yes (5)|Yes (5)|Yes (5)|Yes (5)|Yes (5, 6)|No|Yes|No|Sometimes (2)|
3030
|Switch|Yes|Yes|Yes|Yes|No|No|No|No|Yes|Sometimes (2)|
3131

3232
>__Notes__:
@@ -35,7 +35,7 @@ The following Devices are supported in a way that doesn't require specialized su
3535
>3. XInput controllers on Mac currently require the installation of the [Xbox Controller Driver for macOS](https://github.com/360Controller/360Controller). Only USB connections are supported by that driver, no wireless dongles. However, the latest generation of Xbox One controllers natively support Bluetooth, and are natively supported on Macs as HIDs without any additional drivers when connected via Bluetooth.
3636
>4. This includes any XInput-compatible Device.
3737
>5. Unity doesn't support the gyro or accelerometer on PS4 controllers on platforms other than the PlayStation 4 console at the moment. Also, Unity doesn't support the *DualShock 4 USB Wireless Adaptor*.
38-
>6. Unity supports Mfi certified controllers on iOS.
38+
>6. Unity supports Mfi certified controllers on iOS. Xbox One and PS4 controllers are only supported on iOS 13 or higher.
3939
>7. Consoles are supported using separate packages. You need to install these packages in your Project to enable console support.
4040
4141
### WebGL

Packages/com.unity.inputsystem/InputSystem/InputSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,11 +2867,11 @@ private static void RunInitialUpdate()
28672867
#if !UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION
28682868
private static void PerformDefaultPluginInitialization()
28692869
{
2870-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA
2870+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_IOS
28712871
XInputSupport.Initialize();
28722872
#endif
28732873

2874-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_PS4 || UNITY_WSA
2874+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_PS4 || UNITY_WSA || UNITY_IOS
28752875
DualShockSupport.Initialize();
28762876
#endif
28772877

Packages/com.unity.inputsystem/InputSystem/Plugins/iOS/IOSGameController.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#if UNITY_EDITOR || UNITY_IOS || UNITY_TVOS
1+
#if UNITY_EDITOR || UNITY_IOS || UNITY_TVOS || PACKAGE_DOCS_GENERATION
22
using System.Runtime.InteropServices;
3+
using UnityEngine.InputSystem.DualShock;
34
using UnityEngine.InputSystem.Layouts;
45
using UnityEngine.InputSystem.LowLevel;
56
using UnityEngine.InputSystem.iOS.LowLevel;
@@ -105,10 +106,35 @@ public iOSGameControllerState WithAxis(iOSAxis axis, float value)
105106

106107
namespace UnityEngine.InputSystem.iOS
107108
{
109+
/// <summary>
110+
/// A generic Gamepad connected to an iOS device.
111+
/// </summary>
112+
/// <remarks>
113+
/// Any MFi-certified Gamepad which is not an <see cref="XboxOneGampadiOS"/> or <see cref="DualShock4GampadiOS"/> will
114+
/// be represented as an iOSGameController.
115+
/// </remarks>
108116
[InputControlLayout(stateType = typeof(iOSGameControllerState), displayName = "iOS Gamepad")]
109117
[Scripting.Preserve]
110118
public class iOSGameController : Gamepad
111119
{
112120
}
121+
122+
/// <summary>
123+
/// An Xbox One Bluetooth controller connected to an iOS device.
124+
/// </summary>
125+
[InputControlLayout(stateType = typeof(iOSGameControllerState), displayName = "iOS Xbox One Gamepad")]
126+
[Scripting.Preserve]
127+
public class XboxOneGampadiOS : UnityEngine.InputSystem.XInput.XInputController
128+
{
129+
}
130+
131+
/// <summary>
132+
/// A PlayStation DualShock 4 controller connected to an iOS device.
133+
/// </summary>
134+
[InputControlLayout(stateType = typeof(iOSGameControllerState), displayName = "iOS DualShock 4 Gamepad")]
135+
[Scripting.Preserve]
136+
public class DualShock4GampadiOS : DualShockGamepad
137+
{
138+
}
113139
}
114140
#endif // UNITY_EDITOR || UNITY_IOS || UNITY_TVOS

Packages/com.unity.inputsystem/InputSystem/Plugins/iOS/iOSSupport.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ public static void Initialize()
1616
matches: new InputDeviceMatcher()
1717
.WithInterface("iOS")
1818
.WithDeviceClass("iOSGameController"));
19+
20+
InputSystem.RegisterLayout<XboxOneGampadiOS>("XboxOneGampadiOS",
21+
matches: new InputDeviceMatcher()
22+
.WithInterface("iOS")
23+
.WithDeviceClass("iOSGameController")
24+
.WithProduct("Xbox Wireless Controller"));
25+
26+
InputSystem.RegisterLayout<DualShock4GampadiOS>("DualShock4GampadiOS",
27+
matches: new InputDeviceMatcher()
28+
.WithInterface("iOS")
29+
.WithDeviceClass("iOSGameController")
30+
.WithProduct("DUALSHOCK 4 Wireless Controller"));
1931
}
2032
}
2133
}

0 commit comments

Comments
 (0)