Skip to content

Commit 1943582

Browse files
FIX: OnScreenStick isolated dynamic origin hit detection. (#2341)
Co-authored-by: Rita Merkl <127492464+ritamerkl@users.noreply.github.com>
1 parent 42bf05a commit 1943582

3 files changed

Lines changed: 38 additions & 10 deletions

File tree

Assets/Tests/InputSystem/Plugins/OnScreenTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,40 @@ public IEnumerator Devices_OnScreenStickDoesNotReceivePointerUpEventsInIsolatedM
582582
Assert.That(stick.gameObject.GetComponent<RectTransform>().anchoredPosition, Is.Not.EqualTo(stickOriginPosition));
583583
}
584584

585+
[UnityTest]
586+
[Category("Devices")]
587+
public IEnumerator OnScreenStick_IsolateMode_ShouldCastRayToChild()
588+
{
589+
InputSystem.AddDevice<Touchscreen>();
590+
591+
var uiTestScene = new UITestScene(this);
592+
593+
var stickRect = uiTestScene.AddImage("StickParent");
594+
var stick = stickRect.gameObject.AddComponent<OnScreenStick>();
595+
stick.controlPath = "<Gamepad>/leftStick";
596+
stick.useIsolatedInputActions = true;
597+
598+
var childGO = new GameObject("StickImage", typeof(RectTransform), typeof(Image));
599+
var childRect = childGO.GetComponent<RectTransform>();
600+
childRect.SetParent(stickRect, worldPositionStays: false);
601+
childRect.anchorMin = Vector2.zero;
602+
childRect.anchorMax = Vector2.one;
603+
childRect.sizeDelta = Vector2.zero;
604+
childGO.GetComponent<Image>().raycastTarget = true;
605+
606+
var stickOriginPosition = stickRect.anchoredPosition;
607+
608+
// Ensure that the OnScreenStick component has been started.
609+
yield return null;
610+
611+
yield return uiTestScene.PressAndDrag(childRect, new Vector2(50, 0));
612+
613+
// Allow one more frame for queued events to be processed.
614+
yield return null;
615+
616+
Assert.That(stickRect.anchoredPosition, Is.Not.EqualTo(stickOriginPosition));
617+
}
618+
585619
// https://fogbugz.unity3d.com/f/cases/1305016/
586620
[Test]
587621
[Category("Devices")]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3131
- Align title font size with toolbar style in `Input Action` window.
3232
- Updated Action Properties headers to use colors consistent with GameObject component headers.
3333
- Fixed misaligned Virtual Cursor when changing resolution [ISXB-1119](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1119)
34+
- Fixed OnScreenStick ignoring dynamic-origin presses when isolated input actions were enabled. [ISXB-1027](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1027)
3435
- Fixed an issue where `IndexOutOfRangeException` was thrown from `InputManagerStateMonitors.AddStateChangeMonitor` when attempting to enable an action map from within an `InputAction.cancel` callback when using control schemes. (ISXB-1767).
3536

3637
### Added

Packages/com.unity.inputsystem/InputSystem/Plugins/OnScreen/OnScreenStick.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,9 @@ private void OnPointerDown(InputAction.CallbackContext ctx)
249249
if (m_RaycastResults.Count == 0)
250250
return;
251251

252-
var stickSelected = false;
253-
foreach (var result in m_RaycastResults)
254-
{
255-
if (result.gameObject != gameObject) continue;
256-
257-
stickSelected = true;
258-
break;
259-
}
260-
261-
if (!stickSelected)
252+
// Only accept selection if the top-most UI hit is within this stick's hierarchy.
253+
var topResult = m_RaycastResults[0];
254+
if (!topResult.gameObject.transform.IsChildOf(transform))
262255
return;
263256

264257
BeginInteraction(screenPosition, GetCameraFromCanvas());

0 commit comments

Comments
 (0)