Skip to content

Commit d9b8804

Browse files
Added test for UI navigation when localMultiPlayerRoot is set null.
Added a new test to verify UI navigation and submit actions using a gamepad when the event system's playerRoot (localMultiPlayerRoot) is set and when it is null. Ensures navigation and submit functionality work correctly in both scenarios.
1 parent b40d8c1 commit d9b8804

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

Assets/Tests/InputSystem/Plugins/UITests.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,96 @@ public void UI_ClickDraggingMouseDoesNotAllocateGCMemory()
27642764
}, Is.Not.AllocatingGCMemory());
27652765
}
27662766

2767+
[UnityTest]
2768+
[Category("UI")]
2769+
public IEnumerator UI_CanNavigateUI_WithLocalMultiPlayerRoot_Null_UsingGamepads()
2770+
{
2771+
// Setup gamepad for navigation
2772+
var gamepad = InputSystem.AddDevice<Gamepad>();
2773+
var scene = CreateTestUI(makeSelectable: true);
2774+
2775+
// Create actions for navigation
2776+
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
2777+
var map = asset.AddActionMap("map");
2778+
var moveAction = map.AddAction("move", type: InputActionType.Value, binding: "<Gamepad>/leftStick");
2779+
var submitAction = map.AddAction("submit", type: InputActionType.Button, binding: "<Gamepad>/buttonSouth");
2780+
2781+
// Assign actions to the UI module
2782+
scene.uiModule.move = InputActionReference.Create(moveAction);
2783+
scene.uiModule.submit = InputActionReference.Create(submitAction);
2784+
map.Enable();
2785+
2786+
// Assign localMultiPlayerRoot to a value
2787+
scene.eventSystem.playerRoot = scene.parentGameObject;
2788+
2789+
// Initial selection to left object
2790+
scene.eventSystem.SetSelectedGameObject(scene.leftGameObject);
2791+
yield return null;
2792+
2793+
// Press right to navigate to right object
2794+
Set(gamepad.leftStick, new Vector2(1, 0));
2795+
yield return null;
2796+
2797+
// Verify navigation when localMultiPlayerRoot is set
2798+
Assert.That(scene.eventSystem.currentSelectedGameObject, Is.SameAs(scene.rightGameObject),"Right navigation did not work when localMultiPlayerRoot was set");
2799+
2800+
// Press left to navigate back to left object
2801+
Set(gamepad.leftStick, Vector2.zero);
2802+
yield return null;
2803+
Set(gamepad.leftStick, new Vector2(-1, 0));
2804+
yield return null;
2805+
2806+
// Verify navigation
2807+
Assert.That(scene.eventSystem.currentSelectedGameObject, Is.SameAs(scene.leftGameObject),"Left navigation did not work when localMultiPlayerRoot was set");
2808+
2809+
// Test 3: Test up/down navigation
2810+
Set(gamepad.leftStick, Vector2.zero);
2811+
yield return null;
2812+
Set(gamepad.leftStick, new Vector2(0, 1)); // Up
2813+
yield return null;
2814+
Set(gamepad.leftStick, Vector2.zero);
2815+
yield return null;
2816+
Set(gamepad.leftStick, new Vector2(0, -1)); // Down
2817+
yield return null;
2818+
2819+
// Reset stick position for next tests
2820+
Set(gamepad.leftStick, Vector2.zero);
2821+
yield return null;
2822+
2823+
// Test with localMultiPlayerRoot set to null
2824+
scene.eventSystem.playerRoot = null;
2825+
2826+
// Reset selection to left object
2827+
scene.eventSystem.SetSelectedGameObject(scene.leftGameObject);
2828+
yield return null;
2829+
2830+
// Press right to navigate to right object with null root
2831+
Set(gamepad.leftStick, new Vector2(1, 0));
2832+
yield return null;
2833+
2834+
// Verify navigation still works when localMultiPlayerRoot is null
2835+
Assert.That(scene.eventSystem.currentSelectedGameObject, Is.SameAs(scene.rightGameObject),"Right navigation did not work when localMultiPlayerRoot was null");
2836+
2837+
// Press left to navigate back to left object with null root
2838+
Set(gamepad.leftStick, Vector2.zero);
2839+
yield return null;
2840+
Set(gamepad.leftStick, new Vector2(-1, 0));
2841+
yield return null;
2842+
2843+
// Verify navigation
2844+
Assert.That(scene.eventSystem.currentSelectedGameObject, Is.SameAs(scene.leftGameObject),"Left navigation did not work when localMultiPlayerRoot was null");
2845+
2846+
// Test submit functionality works with null root
2847+
PressAndRelease(gamepad.buttonSouth);
2848+
yield return null;
2849+
2850+
// Verify submit event
2851+
Assert.That(scene.leftChildReceiver.events, Has.Exactly(1).With.Property("type").EqualTo(EventType.Submit),"Submit event was not received when localMultiPlayerRoot was null");
2852+
2853+
// Checking that localMultiPlayerRoot is null
2854+
Assert.AreEqual(null, scene.uiModule.localMultiPlayerRoot);
2855+
}
2856+
27672857
[UnityTest]
27682858
[Category("UI")]
27692859
// Check that two players can have separate UI, and that both selections will stay active when

0 commit comments

Comments
 (0)