Skip to content

Commit 9845f9e

Browse files
authored
Fixed bug where objects with disabled components could cause pointers to become focus locked (#9945)
1 parent 14ad116 commit 9845f9e

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

Assets/MRTK/Services/InputSystem/MixedRealityInputSystem.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,13 +1191,14 @@ public void RaisePointerDown(IMixedRealityPointer pointer, MixedRealityInputActi
11911191
IMixedRealityPointerHandler ancestorPointerHandler = null;
11921192
while (currentObject != null && ancestorPointerHandler == null)
11931193
{
1194-
foreach (var component in currentObject.GetComponents<Component>())
1194+
foreach (IMixedRealityPointerHandler handler in currentObject.GetComponents<IMixedRealityPointerHandler>())
11951195
{
1196-
if (component is IMixedRealityPointerHandler handler)
1196+
if(handler is MonoBehaviour behavior && !behavior.enabled)
11971197
{
1198-
ancestorPointerHandler = handler;
1199-
break;
1198+
continue;
12001199
}
1200+
ancestorPointerHandler = handler;
1201+
break;
12011202
}
12021203
currentObject = currentObject.transform.parent;
12031204
}

Assets/MRTK/Tests/PlayModeTests/ObjectManipulatorTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,51 @@ public IEnumerator ObjectManipulatorOneHandMoveFar()
474474
yield return hand.Hide();
475475

476476
}
477+
}
478+
479+
/// <summary>
480+
/// This tests that the cursor doesn't become focus locked when the Object Manipulator component is disabled
481+
/// </summary>
482+
[UnityTest]
483+
public IEnumerator ObjectManipulatorNoFocusOnDisable()
484+
{
485+
// set up cube with manipulation handler
486+
var testObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
487+
testObject.transform.localScale = Vector3.one * 0.2f;
488+
Vector3 initialObjectPosition = new Vector3(0f, 0f, 1f);
489+
testObject.transform.position = initialObjectPosition;
490+
var manipHandler = testObject.AddComponent<ObjectManipulator>();
491+
manipHandler.HostTransform = testObject.transform;
492+
manipHandler.SmoothingFar = false;
493+
manipHandler.SmoothingNear = false;
494+
manipHandler.ManipulationType = ManipulationHandFlags.OneHanded;
495+
496+
// Disable the manipulation handler
497+
manipHandler.enabled = false;
498+
499+
yield return new WaitForFixedUpdate();
500+
yield return null;
501+
502+
// Hand pointing at middle of cube
503+
Vector3 initialHandPosition = new Vector3(0.044f, -0.1f, 0.45f);
504+
TestHand hand = new TestHand(Handedness.Right);
505+
506+
TestUtilities.PlayspaceToOriginLookingForward();
507+
508+
yield return hand.Show(initialHandPosition);
509+
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
477510

511+
Vector3 initialPosition = testObject.transform.position;
512+
yield return hand.SetGesture(ArticulatedHandPose.GestureId.Pinch);
513+
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
514+
515+
Assert.IsFalse(hand.GetPointer<ShellHandRayPointer>().IsFocusLocked);
516+
517+
yield return hand.SetGesture(ArticulatedHandPose.GestureId.Open);
518+
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
519+
520+
Assert.IsFalse(hand.GetPointer<ShellHandRayPointer>().IsFocusLocked);
521+
yield return hand.Hide();
478522
}
479523

480524
/// <summary>

0 commit comments

Comments
 (0)