diff --git a/Assets/Tests/InputSystem/Plugins/UITests.cs b/Assets/Tests/InputSystem/Plugins/UITests.cs index 2928db8c8a..cc9d066098 100644 --- a/Assets/Tests/InputSystem/Plugins/UITests.cs +++ b/Assets/Tests/InputSystem/Plugins/UITests.cs @@ -2871,26 +2871,29 @@ public IEnumerator UI_CanOperateMultiplayerUILocallyUsingGamepads() [UnityTest] [Category("UI")] - public IEnumerator UI_CanDriveUIFromGamepad() + + [TestCase("Gamepad", ExpectedResult = 1)] +#if UNITY_WEBGL || UNITY_EDITOR + [TestCase("WebGLGamepad", ExpectedResult = 1)] +#endif + public IEnumerator UI_CanDriveUIFromGamepad(string deviceLayout) { - var gamepad = InputSystem.AddDevice(); + var gamepad = (Gamepad)InputSystem.AddDevice(deviceLayout); var scene = CreateTestUI(); - var asset = ScriptableObject.CreateInstance(); - var map = asset.AddActionMap("map"); - var moveAction = map.AddAction("move", type: InputActionType.PassThrough, binding: "/*stick"); - var submitAction = map.AddAction("submit", type: InputActionType.PassThrough, binding: "/buttonSouth"); - var cancelAction = map.AddAction("cancel", type: InputActionType.PassThrough, binding: "/buttonEast"); + var actions = new DefaultInputActions(); - scene.uiModule.move = InputActionReference.Create(moveAction); - scene.uiModule.submit = InputActionReference.Create(submitAction); - scene.uiModule.cancel = InputActionReference.Create(cancelAction); + scene.uiModule.move = InputActionReference.Create(actions.UI.Navigate); + scene.uiModule.submit = InputActionReference.Create(actions.UI.Submit); + scene.uiModule.cancel = InputActionReference.Create(actions.UI.Cancel); scene.uiModule.moveRepeatDelay = 0.1f; scene.uiModule.moveRepeatRate = 0.1f; - map.Enable(); + actions.Enable(); + Assert.That(actions.UI.enabled, Is.True); + Assert.That(actions.Player.enabled, Is.True); yield return null; @@ -2913,7 +2916,7 @@ public IEnumerator UI_CanDriveUIFromGamepad() OneEvent("type", EventType.Move), OneEvent("device", gamepad), OneEvent("moveDir", MoveDirection.Right), - OneEvent("moveVector", gamepad.leftStick.ReadValue()))); + OneEvent("moveVector", new Vector2(1.0f, 0.0f)))); Assert.That(scene.rightChildReceiver.events, Is.Empty); #if UNITY_INPUT_SYSTEM_INPUT_MODULE_NAVIGATION_DEVICE_TYPE @@ -2932,7 +2935,7 @@ public IEnumerator UI_CanDriveUIFromGamepad() OneEvent("type", EventType.Move), OneEvent("device", gamepad), OneEvent("moveDir", MoveDirection.Left), - OneEvent("moveVector", gamepad.leftStick.ReadValue()))); + OneEvent("moveVector", new Vector2(-1.0f, 0.0f)))); Assert.That(scene.rightChildReceiver.events, Is.Empty); scene.leftChildReceiver.events.Clear(); @@ -2946,7 +2949,7 @@ public IEnumerator UI_CanDriveUIFromGamepad() OneEvent("type", EventType.Move), OneEvent("device", gamepad), OneEvent("moveDir", MoveDirection.Up), - OneEvent("moveVector", gamepad.leftStick.ReadValue()))); + OneEvent("moveVector", new Vector2(0.0f, 1.0f)))); Assert.That(scene.rightChildReceiver.events, Is.Empty); scene.leftChildReceiver.events.Clear(); @@ -2960,7 +2963,7 @@ public IEnumerator UI_CanDriveUIFromGamepad() OneEvent("type", EventType.Move), OneEvent("device", gamepad), OneEvent("moveDir", MoveDirection.Down), - OneEvent("moveVector", gamepad.leftStick.ReadValue()))); + OneEvent("moveVector", new Vector2(0.0f, -1.0f)))); Assert.That(scene.rightChildReceiver.events, Is.Empty); scene.leftChildReceiver.events.Clear(); @@ -2975,7 +2978,7 @@ public IEnumerator UI_CanDriveUIFromGamepad() OneEvent("type", EventType.Move), OneEvent("device", gamepad), OneEvent("moveDir", MoveDirection.Down), - OneEvent("moveVector", gamepad.leftStick.ReadValue()))); + OneEvent("moveVector", new Vector2(0.0f, -1.0f)))); scene.leftChildReceiver.events.Clear(); @@ -2989,7 +2992,7 @@ public IEnumerator UI_CanDriveUIFromGamepad() OneEvent("type", EventType.Move), OneEvent("device", gamepad), OneEvent("moveDir", MoveDirection.Down), - OneEvent("moveVector", gamepad.leftStick.ReadValue()))); + OneEvent("moveVector", new Vector2(0.0f, -1.0f)))); scene.leftChildReceiver.events.Clear(); @@ -3031,6 +3034,10 @@ public IEnumerator UI_CanDriveUIFromGamepad() Assert.That(scene.leftChildReceiver.events, Is.Empty); Assert.That(scene.rightChildReceiver.events, Is.Empty); + + actions.Disable(); + Assert.That(actions.UI.enabled, Is.False); + Assert.That(actions.Player.enabled, Is.False); } [Test] diff --git a/Assets/Tests/InputSystem/Plugins/WebGLTests.cs b/Assets/Tests/InputSystem/Plugins/WebGLTests.cs index 1e113db3cd..fc3a024a80 100644 --- a/Assets/Tests/InputSystem/Plugins/WebGLTests.cs +++ b/Assets/Tests/InputSystem/Plugins/WebGLTests.cs @@ -43,9 +43,8 @@ public void Devices_SupportsWebGLStandardGamepads() Assert.That(gamepad.leftTrigger.ReadUnprocessedValue(), Is.EqualTo(0.123).Within(0.0001)); Assert.That(gamepad.rightTrigger.ReadUnprocessedValue(), Is.EqualTo(0.234).Within(0.0001)); - AssertStickValues(gamepad.leftStick, new Vector2(0.345f, -0.456f), -0.456f, 0, 0, 0.345f); - AssertStickValues(gamepad.rightStick, new Vector2(0.567f, -0.678f), -0.678f, 0, 0, 0.567f); - + AssertStickValues(gamepad.leftStick, new Vector2(0.345f, -0.456f), 0, 0.456f, 0, 0.345f); + AssertStickValues(gamepad.rightStick, new Vector2(0.567f, -0.678f), 0, 0.678f, 0, 0.567f); InputSystem.QueueStateEvent(gamepad, new WebGLGamepadState { @@ -54,9 +53,8 @@ public void Devices_SupportsWebGLStandardGamepads() }); InputSystem.Update(); - AssertStickValues(gamepad.leftStick, new Vector2(-0.345f, 0.456f), 0, -0.456f, 0.345f, 0); - AssertStickValues(gamepad.rightStick, new Vector2(-0.567f, 0.678f), 0, -0.678f, 0.567f, 0); - + AssertStickValues(gamepad.leftStick, new Vector2(-0.345f, 0.456f), 0.456f, 0, 0.345f, 0); + AssertStickValues(gamepad.rightStick, new Vector2(-0.567f, 0.678f), 0.678f, 0, 0.567f, 0); // Test all buttons. AssertButtonPress(gamepad, new WebGLGamepadState().WithButton(GamepadButton.South), gamepad[GamepadButton.South]); diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 2b7ac9ed00..f898f13d08 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -21,6 +21,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed an issue when providing JoinPlayer with a specific split screen index. [ISXB-897](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-897) - Fixed Inspector Window being refreshed all the time when a PlayerInput component is present with Invoke Unity Events nofication mode chosen [ISXB-1448](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1448) - Fixed an issue where an action with a name containing a slash "/" could not be found via `InputActionAsset.FindAction(string,bool)`. [ISXB-1306](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1306). +- Fixed Gamepad stick up/down inputs that were not recognized in WebGL. [ISXB-1090](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1090) ## [1.14.0] - 2025-03-20 diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/WebGL/WebGLGamepad.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/WebGL/WebGLGamepad.cs index fc15b76025..c26ccbe8a9 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/WebGL/WebGLGamepad.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/WebGL/WebGLGamepad.cs @@ -19,11 +19,11 @@ internal unsafe struct WebGLGamepadState : IInputStateTypeInfo [InputControl(name = "leftStick", offset = 0)] [InputControl(name = "rightStick", offset = 8)] [InputControl(name = "leftStick/y", parameters = "invert")] - [InputControl(name = "leftStick/up", parameters = "clamp=2,clampMin=0,clampMax=1,invert")] - [InputControl(name = "leftStick/down", parameters = "clamp=2,clampMin=-1,clampMax=0,invert=false")] + [InputControl(name = "leftStick/up", parameters = "clamp=2,clampMin=-1,clampMax=0,invert")] + [InputControl(name = "leftStick/down", parameters = "clamp=2,clampMin=0,clampMax=1,invert=false")] [InputControl(name = "rightStick/y", parameters = "invert")] - [InputControl(name = "rightStick/up", parameters = "clamp=2,clampMin=0,clampMax=1,invert")] - [InputControl(name = "rightStick/down", parameters = "clamp=2,clampMin=-1,clampMax=0,invert=false")] + [InputControl(name = "rightStick/up", parameters = "clamp=2,clampMin=-1,clampMax=0,invert")] + [InputControl(name = "rightStick/down", parameters = "clamp=2,clampMin=0,clampMax=1,invert=false")] // All the buttons we need to bump from single bits to full floats and reset bit offsets. [InputControl(name = "buttonSouth", offset = ButtonOffset + 0 * 4, bit = 0, format = "FLT")] [InputControl(name = "buttonEast", offset = ButtonOffset + 1 * 4, bit = 0, format = "FLT")]