|
11 | 11 | using UnityEngine.InputSystem.LowLevel; |
12 | 12 | using UnityEngine.InputSystem.UI; |
13 | 13 | using UnityEngine.InputSystem.Utilities; |
| 14 | +using UnityEngine.Profiling; |
14 | 15 | using UnityEngine.TestTools; |
| 16 | +using UnityEngine.TestTools.Constraints; |
15 | 17 | using UnityEngine.UI; |
16 | 18 | using TouchPhase = UnityEngine.InputSystem.TouchPhase; |
| 19 | +using Is = UnityEngine.TestTools.Constraints.Is; |
17 | 20 |
|
18 | 21 | #pragma warning disable CS0649 |
19 | 22 | ////TODO: app focus handling |
@@ -113,8 +116,8 @@ private static TestObjects CreateScene(int minY = 0 , int maxY = 480) |
113 | 116 | } |
114 | 117 |
|
115 | 118 | [UnityTest] |
116 | | - [Category("Actions")] |
117 | | - public IEnumerator Actions_CanDriveUIFromMouse() |
| 119 | + [Category("UI")] |
| 120 | + public IEnumerator UI_CanDriveUIFromMouse() |
118 | 121 | { |
119 | 122 | // Create devices. |
120 | 123 | var mouse = InputSystem.AddDevice<Mouse>(); |
@@ -254,8 +257,8 @@ public IEnumerator Actions_CanDriveUIFromMouse() |
254 | 257 | } |
255 | 258 |
|
256 | 259 | [UnityTest] |
257 | | - [Category("Actions")] |
258 | | - public IEnumerator Actions_TouchActionsCanDriveUIAndDistinguishMultipleTouches() |
| 260 | + [Category("UI")] |
| 261 | + public IEnumerator UI_TouchActionsCanDriveUIAndDistinguishMultipleTouches() |
259 | 262 | { |
260 | 263 | // Create devices. |
261 | 264 | var touchScreen = InputSystem.AddDevice<Touchscreen>(); |
@@ -441,10 +444,10 @@ public IEnumerator Actions_TouchActionsCanDriveUIAndDistinguishMultipleTouches() |
441 | 444 | } |
442 | 445 |
|
443 | 446 | [UnityTest] |
444 | | - [Category("Actions")] |
| 447 | + [Category("UI")] |
445 | 448 | // Check that two players can have separate UI, and that both selections will stay active when |
446 | 449 | // clicking on UI with the mouse, using MultiPlayerEventSystem.playerRoot to match UI to the players. |
447 | | - public IEnumerator Actions_CanOperateMultiplayerUIGloballyUsingMouse() |
| 450 | + public IEnumerator UI_CanOperateMultiplayerUIGloballyUsingMouse() |
448 | 451 | { |
449 | 452 | var mouse = InputSystem.AddDevice<Mouse>(); |
450 | 453 |
|
@@ -523,10 +526,10 @@ public IEnumerator Actions_CanOperateMultiplayerUIGloballyUsingMouse() |
523 | 526 | } |
524 | 527 |
|
525 | 528 | [UnityTest] |
526 | | - [Category("Actions")] |
| 529 | + [Category("UI")] |
527 | 530 | // Check that two players can have separate UI and control it using separate gamepads, using |
528 | 531 | // MultiplayerEventSystem. |
529 | | - public IEnumerator Actions_CanOperateMultiplayerUILocallyUsingGamepads() |
| 532 | + public IEnumerator UI_CanOperateMultiplayerUILocallyUsingGamepads() |
530 | 533 | { |
531 | 534 | // Create devices. |
532 | 535 | var gamepads = new[] { InputSystem.AddDevice<Gamepad>(), InputSystem.AddDevice<Gamepad>() }; |
@@ -638,8 +641,8 @@ public IEnumerator Actions_CanOperateMultiplayerUILocallyUsingGamepads() |
638 | 641 | } |
639 | 642 |
|
640 | 643 | [UnityTest] |
641 | | - [Category("Actions")] |
642 | | - public IEnumerator Actions_CanDriveUIFromGamepad() |
| 644 | + [Category("UI")] |
| 645 | + public IEnumerator UI_CanDriveUIFromGamepad() |
643 | 646 | { |
644 | 647 | // Create devices. |
645 | 648 | var gamepad = InputSystem.AddDevice<Gamepad>(); |
@@ -741,8 +744,8 @@ public IEnumerator Actions_CanDriveUIFromGamepad() |
741 | 744 | } |
742 | 745 |
|
743 | 746 | [Test] |
744 | | - [Category("Actions")] |
745 | | - public void Actions_CanReassignUIActions() |
| 747 | + [Category("UI")] |
| 748 | + public void UI_CanReassignUIActions() |
746 | 749 | { |
747 | 750 | var go = new GameObject(); |
748 | 751 | go.AddComponent<EventSystem>(); |
@@ -789,6 +792,46 @@ public void Actions_CanReassignUIActions() |
789 | 792 | Assert.That(uiModule.point?.action, Is.Null); |
790 | 793 | } |
791 | 794 |
|
| 795 | + [Test] |
| 796 | + [Category("UI")] |
| 797 | + [Retry(2)] // Warm up JIT |
| 798 | + public void UI_MovingAndClickingMouseDoesNotAllocateGCMemory() |
| 799 | + { |
| 800 | + var mouse = InputSystem.AddDevice<Mouse>(); |
| 801 | + |
| 802 | + var actions = ScriptableObject.CreateInstance<InputActionAsset>(); |
| 803 | + var uiActions = actions.AddActionMap("UI"); |
| 804 | + var pointAction = uiActions.AddAction("Point", type: InputActionType.PassThrough, binding: "<Mouse>/position"); |
| 805 | + var clickAction = uiActions.AddAction("Click", type: InputActionType.PassThrough, binding: "<Mouse>/leftButton"); |
| 806 | + |
| 807 | + actions.Enable(); |
| 808 | + |
| 809 | + var eventSystemGO = new GameObject(); |
| 810 | + eventSystemGO.AddComponent<EventSystem>(); |
| 811 | + var uiModule = eventSystemGO.AddComponent<InputSystemUIInputModule>(); |
| 812 | + uiModule.actionsAsset = actions; |
| 813 | + uiModule.point = InputActionReference.Create(pointAction); |
| 814 | + uiModule.leftClick = InputActionReference.Create(clickAction); |
| 815 | + |
| 816 | + // We allow the first hit on the UI module to set up internal data structures |
| 817 | + // and thus allocate something. So go and run one event with data on the mouse. |
| 818 | + // Also gets rid of GC noise from the initial input system update. |
| 819 | + InputSystem.QueueStateEvent(mouse, new MouseState { position = new Vector2(1, 2) }); |
| 820 | + InputSystem.Update(); |
| 821 | + |
| 822 | + // Make sure we don't get an allocation from the string literal. |
| 823 | + var kProfilerRegion = "UI_MovingAndClickingMouseDoesNotAllocateMemory"; |
| 824 | + |
| 825 | + Assert.That(() => |
| 826 | + { |
| 827 | + Profiler.BeginSample(kProfilerRegion); |
| 828 | + Set(mouse.position, new Vector2(123, 234)); |
| 829 | + Set(mouse.position, new Vector2(234, 345)); |
| 830 | + Press(mouse.leftButton); |
| 831 | + Profiler.EndSample(); |
| 832 | + }, Is.Not.AllocatingGCMemory()); |
| 833 | + } |
| 834 | + |
792 | 835 | // 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. |
793 | 836 | #if !UNITY_EDITOR_WIN |
794 | 837 |
|
@@ -824,8 +867,8 @@ protected override void FinishSetup() |
824 | 867 | } |
825 | 868 |
|
826 | 869 | [UnityTest] |
827 | | - [Category("Actions")] |
828 | | - public IEnumerator Actions_CanDriveUIFromTrackedDevice() |
| 870 | + [Category("UI")] |
| 871 | + public IEnumerator UI_CanDriveUIFromTrackedDevice() |
829 | 872 | { |
830 | 873 | // Create device. |
831 | 874 | InputSystem.RegisterLayout<TestTrackedDevice>(); |
@@ -958,8 +1001,8 @@ public IEnumerator Actions_CanDriveUIFromTrackedDevice() |
958 | 1001 | } |
959 | 1002 |
|
960 | 1003 | [UnityTest] |
961 | | - [Category("Actions")] |
962 | | - public IEnumerator Actions_CanDriveUIFromMultipleTrackedDevices() |
| 1004 | + [Category("UI")] |
| 1005 | + public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices() |
963 | 1006 | { |
964 | 1007 | // Create device. |
965 | 1008 | InputSystem.RegisterLayout<TestTrackedDevice>(); |
|
0 commit comments