|
9 | 9 | using UnityEngine.InputSystem.iOS.LowLevel; |
10 | 10 | using UnityEngine.InputSystem.LowLevel; |
11 | 11 | using UnityEngine.InputSystem.Processors; |
| 12 | +using UnityEngine.InputSystem.Switch; |
12 | 13 | using UnityEngine.InputSystem.XInput; |
13 | 14 | using UnityEngine.TestTools; |
14 | 15 | using UnityEngine.TestTools.Utils; |
@@ -56,13 +57,70 @@ public void Devices_SupportsiOSGamePad(string product, Type deviceType, Type par |
56 | 57 | Assert.That(gamepad.rightTrigger.ReadValue(), Is.EqualTo(0.456).Within(0.000001)); |
57 | 58 |
|
58 | 59 | AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.A), gamepad.buttonSouth); |
| 60 | + AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.A), gamepad.aButton); |
59 | 61 | AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.X), gamepad.buttonWest); |
| 62 | + AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.X), gamepad.xButton); |
60 | 63 | AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.Y), gamepad.buttonNorth); |
| 64 | + AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.Y), gamepad.yButton); |
61 | 65 | AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.B), gamepad.buttonEast); |
| 66 | + AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.B), gamepad.bButton); |
62 | 67 | AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.LeftShoulder), gamepad.leftShoulder); |
63 | 68 | AssertButtonPress(gamepad, new iOSGameControllerState().WithButton(iOSButton.RightShoulder), gamepad.rightShoulder); |
64 | 69 | } |
65 | 70 |
|
| 71 | + [Test] |
| 72 | + [Category("Devices")] |
| 73 | + // this is a new test, as we need to assert the Nintendo layout (e.g. buttonSouth == B button) |
| 74 | + public void Devices_SupportsSwitchProControlleriOS() |
| 75 | + { |
| 76 | + var device = InputSystem.AddDevice( |
| 77 | + new InputDeviceDescription |
| 78 | + { |
| 79 | + interfaceName = "iOS", |
| 80 | + deviceClass = "iOSGameController", |
| 81 | + product = "Pro Controller" |
| 82 | + }); |
| 83 | + Assert.That(device, Is.TypeOf(typeof(SwitchProControlleriOS))); |
| 84 | + Assert.That(device, Is.InstanceOf(typeof(SwitchProController))); |
| 85 | + Assert.That(device, Is.InstanceOf(typeof(Gamepad))); |
| 86 | + |
| 87 | + var gamepad = (SwitchProControlleriOS)device; |
| 88 | + |
| 89 | + InputSystem.QueueStateEvent(gamepad, |
| 90 | + new iOSGameControllerStateSwappedFaceButtons() |
| 91 | + .WithButton(iOSButton.LeftTrigger, true, 0.123f) |
| 92 | + .WithButton(iOSButton.RightTrigger, true, 0.456f) |
| 93 | + .WithAxis(iOSAxis.LeftStickX, 0.789f) |
| 94 | + .WithAxis(iOSAxis.LeftStickY, 0.987f) |
| 95 | + .WithAxis(iOSAxis.RightStickX, 0.654f) |
| 96 | + .WithAxis(iOSAxis.RightStickY, 0.321f)); |
| 97 | + InputSystem.Update(); |
| 98 | + |
| 99 | + var leftStickDeadzone = gamepad.leftStick.TryGetProcessor<StickDeadzoneProcessor>(); |
| 100 | + var rightStickDeadzone = gamepad.leftStick.TryGetProcessor<StickDeadzoneProcessor>(); |
| 101 | + |
| 102 | + Assert.That(gamepad.leftStick.ReadValue(), Is.EqualTo(leftStickDeadzone.Process(new Vector2(0.789f, 0.987f)))); |
| 103 | + Assert.That(gamepad.rightStick.ReadValue(), Is.EqualTo(rightStickDeadzone.Process(new Vector2(0.654f, 0.321f)))); |
| 104 | + Assert.That(gamepad.leftTrigger.ReadValue(), Is.EqualTo(0.123).Within(0.000001)); |
| 105 | + Assert.That(gamepad.rightTrigger.ReadValue(), Is.EqualTo(0.456).Within(0.000001)); |
| 106 | + // testing for Pro Controller layout... |
| 107 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.A), gamepad.buttonEast); |
| 108 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.A), gamepad.aButton); |
| 109 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.X), gamepad.buttonNorth); |
| 110 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.X), gamepad.xButton); |
| 111 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.Y), gamepad.buttonWest); |
| 112 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.Y), gamepad.yButton); |
| 113 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.B), gamepad.buttonSouth); |
| 114 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.B), gamepad.bButton); |
| 115 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.LeftShoulder), gamepad.leftShoulder); |
| 116 | + AssertButtonPress(gamepad, new iOSGameControllerStateSwappedFaceButtons().WithButton(iOSButton.RightShoulder), gamepad.rightShoulder); |
| 117 | + Assert.Contains("Submit", gamepad.buttonEast.usages.m_Array); |
| 118 | + Assert.Contains("PrimaryAction", gamepad.aButton.usages.m_Array); |
| 119 | + Assert.Contains("Back", gamepad.bButton.usages.m_Array); |
| 120 | + Assert.Contains("Cancel", gamepad.bButton.usages.m_Array); |
| 121 | + Assert.Contains("SecondaryAction", gamepad.yButton.usages.m_Array); |
| 122 | + } |
| 123 | + |
66 | 124 | [Test] |
67 | 125 | [Category("Devices")] |
68 | 126 | [TestCase("Gravity", typeof(GravitySensor))] |
|
0 commit comments