From 36e066e89a11e5daf5f18ba39b8173588101cfcc Mon Sep 17 00:00:00 2001 From: Matthew Davey Date: Thu, 8 Jun 2023 09:37:58 -0400 Subject: [PATCH] Lower bar for displayIndex support to 2022.3 --- Assets/Tests/InputSystem/Plugins/UITests.cs | 4 ++-- Packages/com.unity.inputsystem/CHANGELOG.md | 3 +++ .../Plugins/UI/ExtendedPointerEventData.cs | 8 ++++---- .../Plugins/UI/InputSystemUIInputModule.cs | 18 +++++++++--------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Assets/Tests/InputSystem/Plugins/UITests.cs b/Assets/Tests/InputSystem/Plugins/UITests.cs index 7e068ead79..b34dac5f9a 100644 --- a/Assets/Tests/InputSystem/Plugins/UITests.cs +++ b/Assets/Tests/InputSystem/Plugins/UITests.cs @@ -3829,7 +3829,7 @@ public IEnumerator UI_WhenCursorIsLockedToScreenCenter_PointerEnterAndExitEvents } #region Multi Display Tests -#if UNITY_2023_1_OR_NEWER // displayIndex is only available from 2023.1 onwards +#if UNITY_2022_3_OR_NEWER // displayIndex is only available from 2022.3 onwards [UnityTest] #if UNITY_TVOS @@ -4377,7 +4377,7 @@ private static ExtendedPointerEventData ClonePointerEventData(PointerEventData e radius = eventData.radius, radiusVariance = eventData.radiusVariance, #endif -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER displayIndex = eventData.displayIndex, #endif }; diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 10d05422c6..c9d9617a8b 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -10,6 +10,9 @@ however, it has to be formatted properly to pass verification tests. ## [Unreleased] +### Added +- Enabled `displayIndex` support for Unity 2022.3. + ### Fixed - Fixed UI clicks not registering when OS provides multiple input sources for the same event, e.g. on Samsung Dex (case ISX-1416, ISXB-342). diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/ExtendedPointerEventData.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/ExtendedPointerEventData.cs index 5ba0dfd03c..9fd95ef61f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/ExtendedPointerEventData.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/ExtendedPointerEventData.cs @@ -96,7 +96,7 @@ public override string ToString() stringBuilder.AppendLine("altitudeAngle: " + altitudeAngle); stringBuilder.AppendLine("twist: " + twist); #endif - #if UNITY_2023_1_OR_NEWER + #if UNITY_2022_3_OR_NEWER stringBuilder.AppendLine("displayIndex: " + displayIndex); #endif return stringBuilder.ToString(); @@ -142,7 +142,7 @@ internal void ReadDeviceState() altitudeAngle = (pen.tilt.value.y + 1) * Mathf.PI / 2; twist = pen.twist.value * Mathf.PI * 2; #endif - #if UNITY_2023_1_OR_NEWER + #if UNITY_2022_3_OR_NEWER displayIndex = pen.displayIndex.ReadValue(); #endif } @@ -153,7 +153,7 @@ internal void ReadDeviceState() pressure = touchControl.pressure.magnitude; radius = touchControl.radius.value; #endif - #if UNITY_2023_1_OR_NEWER + #if UNITY_2022_3_OR_NEWER displayIndex = touchControl.displayIndex.ReadValue(); #endif } @@ -164,7 +164,7 @@ internal void ReadDeviceState() pressure = touchscreen.pressure.magnitude; radius = touchscreen.radius.value; #endif - #if UNITY_2023_1_OR_NEWER + #if UNITY_2022_3_OR_NEWER displayIndex = touchscreen.displayIndex.ReadValue(); #endif } diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs index 25547f09ff..02390902a6 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs @@ -1737,7 +1737,7 @@ private int GetPointerStateIndexFor(InputControl control, bool createIfNotExists eventData.pointerType = pointerType; eventData.pointerId = pointerId; eventData.touchId = touchId; -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER eventData.displayIndex = displayIndex; #endif @@ -1833,7 +1833,7 @@ private int AllocatePointer(int pointerId, int displayIndex, int touchId, UIPoin eventData = new ExtendedPointerEventData(eventSystem); eventData.pointerId = pointerId; -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER eventData.displayIndex = displayIndex; #endif eventData.touchId = touchId; @@ -1959,7 +1959,7 @@ private void OnPointCallback(InputAction.CallbackContext context) ref var state = ref GetPointerStateForIndex(index); state.screenPosition = context.ReadValue(); -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER state.eventData.displayIndex = GetDisplayIndexFor(context.control); #endif } @@ -1990,7 +1990,7 @@ private void OnLeftClickCallback(InputAction.CallbackContext context) state.changedThisFrame = true; if (IgnoreNextClick(ref context, wasPressed)) state.leftButton.ignoreNextClick = true; -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER state.eventData.displayIndex = GetDisplayIndexFor(context.control); #endif } @@ -2007,7 +2007,7 @@ private void OnRightClickCallback(InputAction.CallbackContext context) state.changedThisFrame = true; if (IgnoreNextClick(ref context, wasPressed)) state.rightButton.ignoreNextClick = true; -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER state.eventData.displayIndex = GetDisplayIndexFor(context.control); #endif } @@ -2024,7 +2024,7 @@ private void OnMiddleClickCallback(InputAction.CallbackContext context) state.changedThisFrame = true; if (IgnoreNextClick(ref context, wasPressed)) state.middleButton.ignoreNextClick = true; -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER state.eventData.displayIndex = GetDisplayIndexFor(context.control); #endif } @@ -2055,7 +2055,7 @@ private void OnScrollCallback(InputAction.CallbackContext context) // The old input system reported scroll deltas in lines, we report pixels. // Need to scale as the UI system expects lines. state.scrollDelta = context.ReadValue() * (1 / kPixelPerLine); -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER state.eventData.displayIndex = GetDisplayIndexFor(context.control); #endif } @@ -2074,7 +2074,7 @@ private void OnTrackedDeviceOrientationCallback(InputAction.CallbackContext cont ref var state = ref GetPointerStateForIndex(index); state.worldOrientation = context.ReadValue(); -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER state.eventData.displayIndex = GetDisplayIndexFor(context.control); #endif } @@ -2087,7 +2087,7 @@ private void OnTrackedDevicePositionCallback(InputAction.CallbackContext context ref var state = ref GetPointerStateForIndex(index); state.worldPosition = context.ReadValue(); -#if UNITY_2023_1_OR_NEWER +#if UNITY_2022_3_OR_NEWER state.eventData.displayIndex = GetDisplayIndexFor(context.control); #endif }