Skip to content

Commit 0f0bf61

Browse files
Refactor to have new SwitchProController Gamepad with remapped ABXY buttons
1 parent f8f6aa4 commit 0f0bf61

File tree

5 files changed

+40
-58
lines changed

5 files changed

+40
-58
lines changed

Assets/Tests/InputSystem/Plugins/iOSTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void Devices_SupportsSwitchProControlleriOS()
8080
product = "Pro Controller"
8181
});
8282
Assert.That(device, Is.TypeOf(typeof(SwitchProControlleriOS)));
83+
Assert.That(device, Is.InstanceOf(typeof(SwitchProController)));
8384
Assert.That(device, Is.InstanceOf(typeof(Gamepad)));
8485

8586
var gamepad = (SwitchProControlleriOS)device;

Assets/Tests/InputSystem/SwitchTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public void Devices_SupportsSwitchLikeControllers(int vendorId, int productId)
172172
});
173173

174174
Assert.That(device, Is.TypeOf<SwitchProControllerHID>());
175+
Assert.That(device, Is.InstanceOf(typeof(SwitchProController)));
175176
}
176177

177178
#endif

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,4 +806,39 @@ public virtual void SetMotorSpeeds(float lowFrequency, float highFrequency)
806806
private static int s_GamepadCount;
807807
private static Gamepad[] s_Gamepads;
808808
}
809+
810+
/// <summary>
811+
/// Base class for Nintendo Switch Pro Controllers that provides the correct button mappings for Nintendo's face button layout where A is east, B is south, X is north, and Y is west.
812+
/// If you use InputSystem.GetDevice and the ABXY properties to represent the labels on the device, you must query for this class
813+
/// </summary>
814+
public abstract class SwitchProController : Gamepad
815+
{
816+
/// <summary>
817+
/// A Button for a Nintendo Switch Pro Controller.
818+
/// If querying via script, ensure you cast the device to a Switch Pro Controller class, rather than using the Gamepad class.
819+
/// The gamepad class will return the state of buttonSouth, whereas this class returns the state of buttonEast
820+
/// </summary>
821+
public new ButtonControl aButton => buttonEast;
822+
823+
/// <summary>
824+
/// B Button for a Nintendo Switch Pro Controller.
825+
/// If querying via script, ensure you cast the device to a Switch Pro Controller class, rather than using the Gamepad class.
826+
/// The gamepad class will return the state of buttonEast, whereas this class returns the state of buttonSouth
827+
/// </summary>
828+
public new ButtonControl bButton => buttonSouth;
829+
830+
/// <summary>
831+
/// Y Button for a Nintendo Switch Pro Controller.
832+
/// If querying via script, ensure you cast the device to a Switch Pro Controller class, rather than using the Gamepad class.
833+
/// The gamepad class will return the state of buttonNorth, whereas this class returns the state of buttonWest
834+
/// </summary>
835+
public new ButtonControl yButton => buttonWest;
836+
837+
/// <summary>
838+
/// X Button for a Nintendo Switch Pro Controller.
839+
/// If querying via script, ensure you cast the device to a Switch Pro Controller class, rather than using the Gamepad class.
840+
/// The gamepad class will return the state of buttonWest, whereas this class returns the state of buttonNorth
841+
/// </summary>
842+
public new ButtonControl xButton => buttonNorth;
843+
}
809844
}

Packages/com.unity.inputsystem/InputSystem/Plugins/Switch/SwitchProControllerHID.cs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -147,42 +147,14 @@ namespace UnityEngine.InputSystem.Switch
147147
/// A Nintendo Switch Pro controller connected to a desktop mac/windows PC using the HID interface.
148148
/// </summary>
149149
[InputControlLayout(stateType = typeof(SwitchProControllerHIDInputState), displayName = "Switch Pro Controller")]
150-
public class SwitchProControllerHID : Gamepad, IInputStateCallbackReceiver, IEventPreProcessor
150+
public class SwitchProControllerHID : SwitchProController, IInputStateCallbackReceiver, IEventPreProcessor
151151
{
152152
[InputControl(name = "capture", displayName = "Capture")]
153153
public ButtonControl captureButton { get; protected set; }
154154

155155
[InputControl(name = "home", displayName = "Home")]
156156
public ButtonControl homeButton { get; protected set; }
157157

158-
/// <summary>
159-
/// A Button for a Nintendo Switch Pro Controller.
160-
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
161-
/// The gamepad class will return the state of buttonSouth, whereas this class returns the state of buttonEast
162-
/// </summary>
163-
public new ButtonControl aButton => buttonEast;
164-
165-
/// <summary>
166-
/// A Button for a Nintendo Switch Pro Controller.
167-
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
168-
/// The gamepad class will return the state of buttonEast, whereas this class returns the state of buttonSouth
169-
/// </summary>
170-
public new ButtonControl bButton => buttonSouth;
171-
172-
/// <summary>
173-
/// A Button for a Nintendo Switch Pro Controller.
174-
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
175-
/// The gamepad class will return the state of buttonNorth, whereas this class returns the state of buttonWest
176-
/// </summary>
177-
public new ButtonControl yButton => buttonWest;
178-
179-
/// <summary>
180-
/// A Button for a Nintendo Switch Pro Controller.
181-
/// If querying via script, ensure you cast the device to SwitchProControllerHID, rather than using the Gamepad class.
182-
/// The gamepad class will return the state of buttonWest, whereas this class returns the state of buttonNorth
183-
/// </summary>
184-
public new ButtonControl xButton => buttonNorth;
185-
186158
protected override void OnAdded()
187159
{
188160
base.OnAdded();

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

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -198,38 +198,11 @@ public class DualSenseGampadiOS : DualShockGamepad
198198

199199
/// <summary>
200200
/// A Switch Pro Controller connected to an iOS device.
201-
/// If you use InputSystem.GetDevice, you must query for this class rather than Gamepad in order for aButton, bButton, yButton and xButton to be correct
201+
/// If you use InputSystem.GetDevice, you must query for SwitchProControlleriOS rather than Gamepad in order for aButton, bButton, yButton and xButton to be correct
202202
/// </summary>
203203
[InputControlLayout(stateType = typeof(iOSGameControllerStateSwappedFaceButtons), displayName = "iOS Switch Pro Controller Gamepad")]
204-
public class SwitchProControlleriOS : Gamepad
204+
public class SwitchProControlleriOS : SwitchProController
205205
{
206-
/// <summary>
207-
/// A Button for a Nintendo Switch Pro Controller.
208-
/// If querying via script, ensure you cast the device to SwitchProControlleriOS, rather than using the Gamepad class.
209-
/// The gamepad class will return the state of buttonSouth, whereas this class returns the state of buttonEast
210-
/// </summary>
211-
public new ButtonControl aButton => buttonEast;
212-
213-
/// <summary>
214-
/// A Button for a Nintendo Switch Pro Controller.
215-
/// If querying via script, ensure you cast the device to SwitchProControlleriOS, rather than using the Gamepad class.
216-
/// The gamepad class will return the state of buttonEast, whereas this class returns the state of buttonSouth
217-
/// </summary>
218-
public new ButtonControl bButton => buttonSouth;
219-
220-
/// <summary>
221-
/// A Button for a Nintendo Switch Pro Controller.
222-
/// If querying via script, ensure you cast the device to SwitchProControlleriOS, rather than using the Gamepad class.
223-
/// The gamepad class will return the state of buttonNorth, whereas this class returns the state of buttonWest
224-
/// </summary>
225-
public new ButtonControl yButton => buttonWest;
226-
227-
/// <summary>
228-
/// A Button for a Nintendo Switch Pro Controller.
229-
/// If querying via script, ensure you cast the device to SwitchProControlleriOS, rather than using the Gamepad class.
230-
/// The gamepad class will return the state of buttonWest, whereas this class returns the state of buttonNorth
231-
/// </summary>
232-
public new ButtonControl xButton => buttonNorth;
233206
}
234207
}
235208
#endif // UNITY_EDITOR || UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS

0 commit comments

Comments
 (0)