Skip to content

Commit e4c05e3

Browse files
authored
Teleport pointer controls the layers masks it raycasts against (#9571)
* Teleport pointer now overriders the layers masks it raycasts against rather than defaulting to the global settings * added unit tests
1 parent de2c03f commit e4c05e3

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Assets/MRTK/SDK/Features/UX/Scripts/Pointers/TeleportPointer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ public override void OnPreSceneQuery()
278278

279279
// Re-enable gravity if we're looking at a hotspot
280280
GravityDistorter.enabled = (TeleportSurfaceResult == TeleportSurfaceResult.HotSpot);
281+
282+
// Set the have the teleport pointer control which layer masks it raycasts against
283+
PrioritizedLayerMasksOverride = PrioritizedLayerMasksOverride ?? new LayerMask[] { ValidLayers | InvalidLayers };
281284
}
282285
}
283286

Assets/MRTK/Tests/PlayModeTests/PointerBehaviorTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// play mode tests in this check.
1212

1313
using Microsoft.MixedReality.Toolkit.Input;
14+
using Microsoft.MixedReality.Toolkit.Teleport;
1415
using Microsoft.MixedReality.Toolkit.Utilities;
1516
using NUnit.Framework;
1617
using System;
@@ -281,6 +282,50 @@ public IEnumerator TestTeleport()
281282
leftHand.Hide();
282283
}
283284

285+
286+
/// <summary>
287+
/// Tests that the teleport pointer functions as expected
288+
/// </summary>
289+
[UnityTest]
290+
public IEnumerator TestTeleportLayers()
291+
{
292+
var iss = PlayModeTestUtilities.GetInputSimulationService();
293+
294+
// Create a floor and make sure it's below the camera
295+
var floor = GameObject.CreatePrimitive(PrimitiveType.Plane);
296+
floor.transform.position = -0.5f * Vector3.up;
297+
298+
// Bring out the right hand and set it to the teleport gesture
299+
TestUtilities.PlayspaceToOriginLookingForward();
300+
float initialForwardPosition = MixedRealityPlayspace.Position.z;
301+
302+
TestHand rightHand = new TestHand(Handedness.Right);
303+
304+
// Make sure the hand is in front of the camera
305+
yield return rightHand.Show(Vector3.forward * 0.6f);
306+
rightHand.SetRotation(Quaternion.identity);
307+
308+
yield return rightHand.SetGesture(ArticulatedHandPose.GestureId.TeleportStart);
309+
// Wait for the hand to animate
310+
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
311+
yield return new WaitForSeconds(1.0f / iss.InputSimulationProfile.HandGestureAnimationSpeed + 0.1f);
312+
313+
TeleportPointer teleportPointer = rightHand.GetPointer<TeleportPointer>();
314+
315+
floor.layer = LayerMask.NameToLayer("Default");
316+
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
317+
Assert.AreEqual(teleportPointer.TeleportSurfaceResult, Physics.TeleportSurfaceResult.Valid);
318+
319+
floor.layer = LayerMask.NameToLayer("Ignore Raycast");
320+
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
321+
Assert.AreEqual(rightHand.GetPointer<TeleportPointer>().TeleportSurfaceResult, Physics.TeleportSurfaceResult.Invalid);
322+
323+
floor.layer = LayerMask.NameToLayer("UI");
324+
yield return PlayModeTestUtilities.WaitForInputSystemUpdate();
325+
Assert.AreEqual(rightHand.GetPointer<TeleportPointer>().TeleportSurfaceResult, Physics.TeleportSurfaceResult.None);
326+
327+
}
328+
284329
/// <summary>
285330
/// Tests that rays can be turned on and off
286331
/// </summary>

0 commit comments

Comments
 (0)