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
75 changes: 59 additions & 16 deletions Assets/Tests/InputSystem/Plugins/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.UI;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Profiling;
using UnityEngine.TestTools;
using UnityEngine.TestTools.Constraints;
using UnityEngine.UI;
using TouchPhase = UnityEngine.InputSystem.TouchPhase;
using Is = UnityEngine.TestTools.Constraints.Is;

#pragma warning disable CS0649
////TODO: app focus handling
Expand Down Expand Up @@ -113,8 +116,8 @@ private static TestObjects CreateScene(int minY = 0 , int maxY = 480)
}

[UnityTest]
[Category("Actions")]
public IEnumerator Actions_CanDriveUIFromMouse()
[Category("UI")]
public IEnumerator UI_CanDriveUIFromMouse()
{
// Create devices.
var mouse = InputSystem.AddDevice<Mouse>();
Expand Down Expand Up @@ -254,8 +257,8 @@ public IEnumerator Actions_CanDriveUIFromMouse()
}

[UnityTest]
[Category("Actions")]
public IEnumerator Actions_TouchActionsCanDriveUIAndDistinguishMultipleTouches()
[Category("UI")]
public IEnumerator UI_TouchActionsCanDriveUIAndDistinguishMultipleTouches()
{
// Create devices.
var touchScreen = InputSystem.AddDevice<Touchscreen>();
Expand Down Expand Up @@ -441,10 +444,10 @@ public IEnumerator Actions_TouchActionsCanDriveUIAndDistinguishMultipleTouches()
}

[UnityTest]
[Category("Actions")]
[Category("UI")]
// Check that two players can have separate UI, and that both selections will stay active when
// clicking on UI with the mouse, using MultiPlayerEventSystem.playerRoot to match UI to the players.
public IEnumerator Actions_CanOperateMultiplayerUIGloballyUsingMouse()
public IEnumerator UI_CanOperateMultiplayerUIGloballyUsingMouse()
{
var mouse = InputSystem.AddDevice<Mouse>();

Expand Down Expand Up @@ -523,10 +526,10 @@ public IEnumerator Actions_CanOperateMultiplayerUIGloballyUsingMouse()
}

[UnityTest]
[Category("Actions")]
[Category("UI")]
// Check that two players can have separate UI and control it using separate gamepads, using
// MultiplayerEventSystem.
public IEnumerator Actions_CanOperateMultiplayerUILocallyUsingGamepads()
public IEnumerator UI_CanOperateMultiplayerUILocallyUsingGamepads()
{
// Create devices.
var gamepads = new[] { InputSystem.AddDevice<Gamepad>(), InputSystem.AddDevice<Gamepad>() };
Expand Down Expand Up @@ -638,8 +641,8 @@ public IEnumerator Actions_CanOperateMultiplayerUILocallyUsingGamepads()
}

[UnityTest]
[Category("Actions")]
public IEnumerator Actions_CanDriveUIFromGamepad()
[Category("UI")]
public IEnumerator UI_CanDriveUIFromGamepad()
{
// Create devices.
var gamepad = InputSystem.AddDevice<Gamepad>();
Expand Down Expand Up @@ -741,8 +744,8 @@ public IEnumerator Actions_CanDriveUIFromGamepad()
}

[Test]
[Category("Actions")]
public void Actions_CanReassignUIActions()
[Category("UI")]
public void UI_CanReassignUIActions()
{
var go = new GameObject();
go.AddComponent<EventSystem>();
Expand Down Expand Up @@ -789,6 +792,46 @@ public void Actions_CanReassignUIActions()
Assert.That(uiModule.point?.action, Is.Null);
}

[Test]
[Category("UI")]
[Retry(2)] // Warm up JIT
public void UI_MovingAndClickingMouseDoesNotAllocateGCMemory()
{
var mouse = InputSystem.AddDevice<Mouse>();

var actions = ScriptableObject.CreateInstance<InputActionAsset>();
var uiActions = actions.AddActionMap("UI");
var pointAction = uiActions.AddAction("Point", type: InputActionType.PassThrough, binding: "<Mouse>/position");
var clickAction = uiActions.AddAction("Click", type: InputActionType.PassThrough, binding: "<Mouse>/leftButton");

actions.Enable();

var eventSystemGO = new GameObject();
eventSystemGO.AddComponent<EventSystem>();
var uiModule = eventSystemGO.AddComponent<InputSystemUIInputModule>();
uiModule.actionsAsset = actions;
uiModule.point = InputActionReference.Create(pointAction);
uiModule.leftClick = InputActionReference.Create(clickAction);

// We allow the first hit on the UI module to set up internal data structures
// and thus allocate something. So go and run one event with data on the mouse.
// Also gets rid of GC noise from the initial input system update.
InputSystem.QueueStateEvent(mouse, new MouseState { position = new Vector2(1, 2) });
InputSystem.Update();

// Make sure we don't get an allocation from the string literal.
var kProfilerRegion = "UI_MovingAndClickingMouseDoesNotAllocateMemory";

Assert.That(() =>
{
Profiler.BeginSample(kProfilerRegion);
Set(mouse.position, new Vector2(123, 234));
Set(mouse.position, new Vector2(234, 345));
Press(mouse.leftButton);
Profiler.EndSample();
}, Is.Not.AllocatingGCMemory());
}

// The tracked device tests fail with NullReferenceException in the windows editor on yamato. I cannot reproduce this locally, so will disable them on windows for now.
#if !UNITY_EDITOR_WIN

Expand Down Expand Up @@ -824,8 +867,8 @@ protected override void FinishSetup()
}

[UnityTest]
[Category("Actions")]
public IEnumerator Actions_CanDriveUIFromTrackedDevice()
[Category("UI")]
public IEnumerator UI_CanDriveUIFromTrackedDevice()
{
// Create device.
InputSystem.RegisterLayout<TestTrackedDevice>();
Expand Down Expand Up @@ -958,8 +1001,8 @@ public IEnumerator Actions_CanDriveUIFromTrackedDevice()
}

[UnityTest]
[Category("Actions")]
public IEnumerator Actions_CanDriveUIFromMultipleTrackedDevices()
[Category("UI")]
public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices()
{
// Create device.
InputSystem.RegisterLayout<TestTrackedDevice>();
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 @@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests.
### Fixed

- XR controllers and HMDs have proper display names in the UI again. This regressed in preview.4 such that all XR controllers were displayed as just "XR Controller" in the UI and all HMDs were displayed as "XR HMD".
- `InputSystemUIInputModule` no longer generates GC heap garbage every time mouse events are processed.

#### Actions

Expand Down
Loading