Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions Assets/Tests/InputSystem/Plugins/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gamepad>();
var gamepad = (Gamepad)InputSystem.AddDevice(deviceLayout);

var scene = CreateTestUI();

var asset = ScriptableObject.CreateInstance<InputActionAsset>();
var map = asset.AddActionMap("map");
var moveAction = map.AddAction("move", type: InputActionType.PassThrough, binding: "<Gamepad>/*stick");
var submitAction = map.AddAction("submit", type: InputActionType.PassThrough, binding: "<Gamepad>/buttonSouth");
var cancelAction = map.AddAction("cancel", type: InputActionType.PassThrough, binding: "<Gamepad>/buttonEast");
Comment on lines -2882 to -2884
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't reflect ou UI default actions setup. That's why I used the ones we use by default.

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;

Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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]
Expand Down
10 changes: 4 additions & 6 deletions Assets/Tests/InputSystem/Plugins/WebGLTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down