Skip to content
Open
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
2 changes: 1 addition & 1 deletion Assets/Tests/InputSystem/Plugins/DeviceSimulatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if UNITY_EDITOR && UNITY_2021_1_OR_NEWER
#if UNITY_EDITOR

using System.Collections;
using System.Reflection;
Expand Down
95 changes: 17 additions & 78 deletions Assets/Tests/InputSystem/Plugins/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
using UnityEditor.SceneManagement;
#endif

#if UNITY_2021_2_OR_NEWER
using UnityEngine.UIElements;
#endif

#pragma warning disable CS0649
////TODO: app focus handling
Expand Down Expand Up @@ -399,13 +397,7 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
}
yield return null;

const int kHaveMovementEvents =
#if UNITY_2021_2_OR_NEWER
1
#else
0
#endif
;
const int kHaveMovementEvents = 1;

Assert.That(scene.leftChildReceiver.events, Has.Count.EqualTo((isTouch ? 3 : 1) + kHaveMovementEvents));
Assert.That(scene.parentReceiver.events, Has.Count.EqualTo(1 + kHaveMovementEvents));
Expand Down Expand Up @@ -486,7 +478,6 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
// Touch has no ability to point without pressing so pointer enter event is followed
// right by pointer down event.

#if UNITY_2021_2_OR_NEWER
// PointerMove.
Assert.That(scene.leftChildReceiver.events[0 + kHaveMovementEvents].type, Is.EqualTo(EventType.PointerMove));
Assert.That(scene.leftChildReceiver.events[0 + kHaveMovementEvents].pointerData.button, Is.EqualTo(PointerEventData.InputButton.Left));
Expand Down Expand Up @@ -514,7 +505,6 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
Assert.That(scene.leftChildReceiver.events[0 + kHaveMovementEvents].pointerData.pointerPressRaycast.gameObject, Is.Null);
Assert.That(scene.leftChildReceiver.events[0 + kHaveMovementEvents].pointerData.pointerPressRaycast.screenPosition,
Is.EqualTo(default(Vector2)).Using(Vector2EqualityComparer.Instance));
#endif

// PointerDown.
Assert.That(scene.leftChildReceiver.events[1 + kHaveMovementEvents].type, Is.EqualTo(EventType.PointerDown));
Expand Down Expand Up @@ -741,7 +731,6 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
AllEvents("pointerCurrentRaycast.screenPosition", secondScreenPosition),

// PointerMove.
#if UNITY_2021_2_OR_NEWER
OneEvent("type", EventType.PointerMove),
OneEvent("dragging", false),
// Again, pointer movement is processed exclusively "from" the left button.
Expand All @@ -755,7 +744,6 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
OneEvent("lastPress", clickButton == PointerEventData.InputButton.Left ? null : scene.leftGameObject),
OneEvent("pointerPressRaycast.gameObject", clickButton == PointerEventData.InputButton.Left ? scene.leftGameObject : null),
OneEvent("pointerPressRaycast.screenPosition", clickButton == PointerEventData.InputButton.Left ? firstScreenPosition : Vector2.zero),
#endif

// BeginDrag.
OneEvent("type", EventType.BeginDrag),
Expand Down Expand Up @@ -788,12 +776,7 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
);

Assert.That(scene.rightChildReceiver.events, Is.Empty);
Assert.That(scene.parentReceiver.events,
EventSequence(
#if UNITY_2021_2_OR_NEWER
OneEvent("type", EventType.PointerMove)
#endif
)
Assert.That(scene.parentReceiver.events, EventSequence(OneEvent("type", EventType.PointerMove))
);

scene.leftChildReceiver.events.Clear();
Expand All @@ -819,12 +802,7 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
Assert.That(scene.eventSystem.IsPointerOverGameObject(pointerId), Is.True);
// Should not have seen pointer enter/exit on parent (we only moved from one of its
// children to another) but *should* have seen a move event.
Assert.That(scene.parentReceiver.events,
EventSequence(
#if UNITY_2021_2_OR_NEWER
OneEvent("type", EventType.PointerMove)
#endif
)
Assert.That(scene.parentReceiver.events, EventSequence(OneEvent("type", EventType.PointerMove))
);

if (isTracked)
Expand Down Expand Up @@ -852,7 +830,6 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
// press positions on the moves will be zero.

// PointerMove.
#if UNITY_2021_2_OR_NEWER
OneEvent("type", EventType.PointerMove),
OneEvent("button", PointerEventData.InputButton.Left),
OneEvent("pointerEnter", scene.leftGameObject),
Expand All @@ -867,7 +844,6 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
OneEvent("dragging", clickButton == PointerEventData.InputButton.Left ? true : false),
OneEvent("pointerPressRaycast.gameObject", clickButton == PointerEventData.InputButton.Left ? scene.leftGameObject : null),
OneEvent("pointerPressRaycast.screenPosition", clickButton == PointerEventData.InputButton.Left ? firstScreenPosition : Vector2.zero),
#endif

// PointerExit.
OneEvent("type", EventType.PointerExit),
Expand Down Expand Up @@ -927,10 +903,8 @@ public IEnumerator UI_CanDriveUIFromPointer(string deviceLayout, UIPointerType p
AllEvents("pointerPressRaycast.gameObject", clickButton == PointerEventData.InputButton.Left ? scene.leftGameObject : null),
AllEvents("pointerPressRaycast.screenPosition", clickButton == PointerEventData.InputButton.Left ? firstScreenPosition : Vector2.zero),

OneEvent("type", EventType.PointerEnter)
#if UNITY_2021_2_OR_NEWER
, OneEvent("type", EventType.PointerMove)
#endif
OneEvent("type", EventType.PointerEnter),
OneEvent("type", EventType.PointerMove)
)
);

Expand Down Expand Up @@ -1892,15 +1866,13 @@ public IEnumerator UI_CanReleaseAndPressTouchesOnSameFrame()
.Matches((UICallbackReceiver.Event e) => e.pointerData.pointerType == UIPointerType.Touch).And
.Matches((UICallbackReceiver.Event e) => e.pointerData.position == secondPosition));

#if UNITY_2021_2_OR_NEWER
Assert.That(scene.rightChildReceiver.events,
Has.Exactly(1).With.Property("type").EqualTo(EventType.PointerMove).And
.Matches((UICallbackReceiver.Event e) => e.pointerData.device == touchScreen).And
.Matches((UICallbackReceiver.Event e) => e.pointerData.touchId == 2).And
.Matches((UICallbackReceiver.Event e) => e.pointerData.pointerId == pointerIdTouch2).And
.Matches((UICallbackReceiver.Event e) => e.pointerData.pointerType == UIPointerType.Touch).And
.Matches((UICallbackReceiver.Event e) => e.pointerData.position == secondPosition));
#endif

// Pointer 3
Assert.That(scene.rightChildReceiver.events,
Expand Down Expand Up @@ -2025,12 +1997,10 @@ public IEnumerator UI_CanUseTouchSimulationWithUI()
AllEvents("pointerType", UIPointerType.Touch),
AllEvents("touchId", 1),
AllEvents("position", scene.From640x480ToScreen(180, 180)),
OneEvent("type", EventType.PointerEnter)
#if UNITY_2021_2_OR_NEWER
, OneEvent("type", EventType.PointerMove)
#endif
, OneEvent("type", EventType.PointerDown)
, OneEvent("type", EventType.InitializePotentialDrag)
OneEvent("type", EventType.PointerEnter),
OneEvent("type", EventType.PointerMove),
OneEvent("type", EventType.PointerDown),
OneEvent("type", EventType.InitializePotentialDrag)
)
);

Expand Down Expand Up @@ -2149,10 +2119,8 @@ public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices()
AllEvents("pointerId", trackedDevice1.deviceId),
AllEvents("device", trackedDevice1),
AllEvents("trackedDeviceOrientation", scene.GetLookAtQuaternion(Vector3.zero, scene.leftGameObject)),
OneEvent("type", EventType.PointerEnter)
#if UNITY_2021_2_OR_NEWER
, OneEvent("type", EventType.PointerMove)
#endif
OneEvent("type", EventType.PointerEnter),
OneEvent("type", EventType.PointerMove)
)
);
Assert.That(scene.rightChildReceiver.events, Is.Empty);
Expand All @@ -2169,10 +2137,8 @@ public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices()
AllEvents("pointerId", trackedDevice2.deviceId),
AllEvents("device", trackedDevice2),
AllEvents("trackedDeviceOrientation", scene.GetLookAtQuaternion(Vector3.zero, scene.leftGameObject, Vector3.left)),
OneEvent("type", EventType.PointerEnter)
#if UNITY_2021_2_OR_NEWER
, OneEvent("type", EventType.PointerMove)
#endif
OneEvent("type", EventType.PointerEnter),
OneEvent("type", EventType.PointerMove)
)
);
Assert.That(scene.rightChildReceiver.events, Is.Empty);
Expand Down Expand Up @@ -2230,9 +2196,7 @@ public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices()
AllEvents("pointerId", trackedDevice1.deviceId),
AllEvents("device", trackedDevice1),
AllEvents("trackedDeviceOrientation", scene.GetLookAtQuaternion(Vector3.zero, scene.rightGameObject)),
#if UNITY_2021_2_OR_NEWER
OneEvent("type", EventType.PointerMove),
#endif
OneEvent("type", EventType.PointerExit)
)
);
Expand All @@ -2242,10 +2206,8 @@ public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices()
AllEvents("pointerId", trackedDevice1.deviceId),
AllEvents("device", trackedDevice1),
AllEvents("trackedDeviceOrientation", scene.GetLookAtQuaternion(Vector3.zero, scene.rightGameObject)),
OneEvent("type", EventType.PointerEnter)
#if UNITY_2021_2_OR_NEWER
, OneEvent("type", EventType.PointerMove)
#endif
OneEvent("type", EventType.PointerEnter),
OneEvent("type", EventType.PointerMove)
)
);

Expand All @@ -2262,9 +2224,7 @@ public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices()
AllEvents("pointerId", trackedDevice2.deviceId),
AllEvents("device", trackedDevice2),
AllEvents("trackedDeviceOrientation", scene.GetLookAtQuaternion(Vector3.zero, scene.rightGameObject, Vector3.right)),
#if UNITY_2021_2_OR_NEWER
OneEvent("type", EventType.PointerMove),
#endif
OneEvent("type", EventType.PointerExit)
)
);
Expand All @@ -2275,9 +2235,7 @@ public IEnumerator UI_CanDriveUIFromMultipleTrackedDevices()
AllEvents("device", trackedDevice2),
AllEvents("trackedDeviceOrientation", scene.GetLookAtQuaternion(Vector3.zero, scene.rightGameObject, Vector3.right)),
OneEvent("type", EventType.PointerEnter)
#if UNITY_2021_2_OR_NEWER
, OneEvent("type", EventType.PointerMove)
#endif
)
);
}
Expand Down Expand Up @@ -2601,12 +2559,7 @@ public IEnumerator UI_CanGetRaycastResultMatchingEvent()
var raycastResult = scene.uiModule.GetLastRaycastResult(trackedDevice.deviceId);
Assert.That(raycastResult.isValid, Is.True);

//2021.2 added an additional move event.
#if UNITY_2021_2_OR_NEWER
Assert.That(scene.leftChildReceiver.events, Has.Count.EqualTo(2));
#else
Assert.That(scene.leftChildReceiver.events, Has.Count.EqualTo(1));
#endif
Assert.That(scene.leftChildReceiver.events[0].pointerData, Is.Not.Null);

var eventRaycastResult = scene.leftChildReceiver.events[0].pointerData.pointerCurrentRaycast;
Expand Down Expand Up @@ -4041,9 +3994,7 @@ public IEnumerator UI_CanOperateUIToolkitInterface_UsingInputSystemUIInputModule
////FIXME: as of a time of writing, this line is broken on trunk due to the bug in UITK
// The bug is https://fogbugz.unity3d.com/f/cases/1323488/
// just adding a define as a safeguard measure to reenable it when trunk goes to next version cycle
#if UNITY_2021_3_OR_NEWER
Assert.That(scrollView.verticalScroller.value, Is.GreaterThan(0));
#endif

// Try a button press with the gamepad.
// NOTE: The current version of UITK does not focus the button automatically. Fix for that is in the pipe.
Expand Down Expand Up @@ -4171,9 +4122,7 @@ public IEnumerator UI_WhenAppLosesAndRegainsFocus_WhileUIButtonIsPressed_UIButto
Assert.That(scene.leftChildReceiver.events,
EventSequence(
OneEvent("type", EventType.PointerEnter),
#if UNITY_2021_2_OR_NEWER
OneEvent("type", EventType.PointerMove),
#endif
OneEvent("type", EventType.PointerDown),
OneEvent("type", EventType.InitializePotentialDrag)
)
Expand Down Expand Up @@ -4636,9 +4585,7 @@ private enum EventType
PointerUp,
PointerEnter,
PointerExit,
#if UNITY_2021_2_OR_NEWER
PointerMove,
#endif
Select,
Deselect,
InitializePotentialDrag,
Expand All @@ -4653,11 +4600,8 @@ private enum EventType
}

private class UICallbackReceiver : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler,
#if UNITY_2021_2_OR_NEWER
IPointerMoveHandler,
#endif
IPointerExitHandler, IPointerUpHandler, IMoveHandler, ISelectHandler, IDeselectHandler, IInitializePotentialDragHandler,
IBeginDragHandler, IDragHandler, IEndDragHandler, IDropHandler, ISubmitHandler, ICancelHandler, IScrollHandler
IPointerMoveHandler, IPointerExitHandler, IPointerUpHandler, IMoveHandler, ISelectHandler, IDeselectHandler,
IInitializePotentialDragHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IDropHandler, ISubmitHandler, ICancelHandler, IScrollHandler
{
public struct Event
{
Expand Down Expand Up @@ -4709,14 +4653,11 @@ public void OnPointerUp(PointerEventData eventData)
events.Add(new Event(EventType.PointerUp, ClonePointerEventData(eventData)));
}

#if UNITY_2021_2_OR_NEWER
public void OnPointerMove(PointerEventData eventData)
{
events.Add(new Event(EventType.PointerMove, ClonePointerEventData(eventData)));
}

#endif

public void OnMove(AxisEventData eventData)
{
events.Add(new Event(EventType.Move, CloneAxisEventData(eventData)));
Expand Down Expand Up @@ -4824,15 +4765,13 @@ private static ExtendedPointerEventData ClonePointerEventData(PointerEventData e
pointerType = extendedEventData.pointerType,
trackedDeviceOrientation = extendedEventData.trackedDeviceOrientation,
trackedDevicePosition = extendedEventData.trackedDevicePosition,
#if UNITY_2021_1_OR_NEWER
pressure = eventData.pressure,
tangentialPressure = eventData.tangentialPressure,
altitudeAngle = eventData.altitudeAngle,
azimuthAngle = eventData.azimuthAngle,
twist = eventData.twist,
radius = eventData.radius,
radiusVariance = eventData.radiusVariance,
#endif
#if UNITY_2022_3_OR_NEWER
displayIndex = eventData.displayIndex,
#endif
Expand Down