diff --git a/Editor/Profiles/TeleportSystem/MixedRealityTeleportSystemProfileInspector.cs b/Editor/Profiles/TeleportSystem/MixedRealityTeleportSystemProfileInspector.cs index bd6ab754a..1dad419c0 100644 --- a/Editor/Profiles/TeleportSystem/MixedRealityTeleportSystemProfileInspector.cs +++ b/Editor/Profiles/TeleportSystem/MixedRealityTeleportSystemProfileInspector.cs @@ -11,12 +11,14 @@ namespace XRTK.Editor.Profiles.TeleportSystem public class MixedRealityTeleportSystemProfileInspector : MixedRealityServiceProfileInspector { private SerializedProperty teleportProvider; + private SerializedProperty teleportAction; protected override void OnEnable() { base.OnEnable(); teleportProvider = serializedObject.FindProperty(nameof(teleportProvider)); + teleportAction = serializedObject.FindProperty(nameof(teleportAction)); } public override void OnInspectorGUI() @@ -27,6 +29,7 @@ public override void OnInspectorGUI() EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(teleportProvider); + EditorGUILayout.PropertyField(teleportAction); serializedObject.ApplyModifiedProperties(); diff --git a/Editor/Profiles/TeleportSystem/MixedRealityTeleportValidationDataProviderProfileInspector.cs b/Editor/Profiles/TeleportSystem/MixedRealityTeleportValidationDataProviderProfileInspector.cs index 259dea9a1..f221c7763 100644 --- a/Editor/Profiles/TeleportSystem/MixedRealityTeleportValidationDataProviderProfileInspector.cs +++ b/Editor/Profiles/TeleportSystem/MixedRealityTeleportValidationDataProviderProfileInspector.cs @@ -13,6 +13,7 @@ public class MixedRealityTeleportValidationDataProviderProfileInspector : BaseMi private SerializedProperty invalidLayers; private SerializedProperty upDirectionThreshold; private SerializedProperty maxDistance; + private SerializedProperty maxHeightDistance; protected override void OnEnable() { @@ -22,6 +23,7 @@ protected override void OnEnable() invalidLayers = serializedObject.FindProperty(nameof(invalidLayers)); upDirectionThreshold = serializedObject.FindProperty(nameof(upDirectionThreshold)); maxDistance = serializedObject.FindProperty(nameof(maxDistance)); + maxHeightDistance = serializedObject.FindProperty(nameof(maxHeightDistance)); } public override void OnInspectorGUI() @@ -34,6 +36,7 @@ public override void OnInspectorGUI() EditorGUILayout.PropertyField(invalidLayers); EditorGUILayout.PropertyField(upDirectionThreshold); EditorGUILayout.PropertyField(maxDistance); + EditorGUILayout.PropertyField(maxHeightDistance); serializedObject.ApplyModifiedProperties(); } diff --git a/Runtime/Definitions/TeleportSystem/MixedRealityTeleportSystemProfile.cs b/Runtime/Definitions/TeleportSystem/MixedRealityTeleportSystemProfile.cs index cefeb1fc1..791242d87 100644 --- a/Runtime/Definitions/TeleportSystem/MixedRealityTeleportSystemProfile.cs +++ b/Runtime/Definitions/TeleportSystem/MixedRealityTeleportSystemProfile.cs @@ -3,6 +3,7 @@ using UnityEngine; using XRTK.Attributes; +using XRTK.Definitions.InputSystem; using XRTK.Definitions.Utilities; using XRTK.Interfaces.TeleportSystem; using XRTK.Interfaces.TeleportSystem.Handlers; @@ -29,5 +30,18 @@ public SystemType TeleportProvider get => teleportProvider; internal set => teleportProvider = value; } + + [SerializeField] + [Tooltip("Input action to trigger a teleport request.")] + private MixedRealityInputAction teleportAction = MixedRealityInputAction.None; + + /// + /// Input action to trigger a teleport request. + /// + public MixedRealityInputAction TeleportAction + { + get => teleportAction; + internal set => teleportAction = value; + } } } diff --git a/Runtime/Definitions/TeleportSystem/MixedRealityTeleportValidationDataProviderProfile.cs b/Runtime/Definitions/TeleportSystem/MixedRealityTeleportValidationDataProviderProfile.cs index 21b06bd68..e8ab4b5d6 100644 --- a/Runtime/Definitions/TeleportSystem/MixedRealityTeleportValidationDataProviderProfile.cs +++ b/Runtime/Definitions/TeleportSystem/MixedRealityTeleportValidationDataProviderProfile.cs @@ -66,5 +66,19 @@ public float MaxDistance get => maxDistance; internal set => maxDistance = value; } + + [SerializeField] + [Min(.1f)] + [Tooltip("The maximum height distance from the player a teleport location can be away.")] + private float maxHeightDistance = 10f; + + /// + /// The maximum height distance from the player a teleport location can be away. + /// + public float MaxHeightDistance + { + get => maxHeightDistance; + internal set => maxHeightDistance = value; + } } } diff --git a/Runtime/Interfaces/TeleportSystem/IMixedRealityTeleportSystem.cs b/Runtime/Interfaces/TeleportSystem/IMixedRealityTeleportSystem.cs index 625c9c8e7..08f09781c 100644 --- a/Runtime/Interfaces/TeleportSystem/IMixedRealityTeleportSystem.cs +++ b/Runtime/Interfaces/TeleportSystem/IMixedRealityTeleportSystem.cs @@ -1,6 +1,7 @@ // Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using XRTK.Definitions.InputSystem; using XRTK.Interfaces.Events; using XRTK.Interfaces.InputSystem; @@ -12,6 +13,12 @@ namespace XRTK.Interfaces.TeleportSystem /// public interface IMixedRealityTeleportSystem : IMixedRealityEventSystem { + /// + /// Gets the used to trigger a teleport + /// request. + /// + MixedRealityInputAction TeleportAction { get; } + /// /// Raise a teleportation request event. /// diff --git a/Runtime/Services/TeleportSystem/MixedRealityTeleportSystem.cs b/Runtime/Services/TeleportSystem/MixedRealityTeleportSystem.cs index e0581791a..970cd5be3 100644 --- a/Runtime/Services/TeleportSystem/MixedRealityTeleportSystem.cs +++ b/Runtime/Services/TeleportSystem/MixedRealityTeleportSystem.cs @@ -1,9 +1,9 @@ // Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using System; using UnityEngine; using UnityEngine.EventSystems; +using XRTK.Definitions.InputSystem; using XRTK.Definitions.TeleportSystem; using XRTK.Definitions.Utilities; using XRTK.EventDatum.Teleport; @@ -30,6 +30,7 @@ public MixedRealityTeleportSystem(MixedRealityTeleportSystemProfile profile) : base(profile) { teleportProvider = profile.TeleportProvider?.Type == null ? null : teleportProvider = profile.TeleportProvider; + TeleportAction = profile.TeleportAction; } private readonly SystemType teleportProvider; @@ -125,6 +126,9 @@ public override void Unregister(GameObject listener) #region IMixedRealityTeleportSystem Implementation + /// + public MixedRealityInputAction TeleportAction { get; private set; } + private static readonly ExecuteEvents.EventFunction OnTeleportRequestHandler = delegate (IMixedRealityTeleportHandler handler, BaseEventData eventData) { diff --git a/Runtime/Services/TeleportSystem/MixedRealityTeleportValidationDataProvider.cs b/Runtime/Services/TeleportSystem/MixedRealityTeleportValidationDataProvider.cs index f2701bad0..0145d0ce2 100644 --- a/Runtime/Services/TeleportSystem/MixedRealityTeleportValidationDataProvider.cs +++ b/Runtime/Services/TeleportSystem/MixedRealityTeleportValidationDataProvider.cs @@ -23,12 +23,14 @@ public MixedRealityTeleportValidationDataProvider(string name, uint priority, Mi invalidLayers = profile.InvalidLayers; upDirectionThreshold = profile.UpDirectionThreshold; maxDistanceSquare = profile.MaxDistance * profile.MaxDistance; + maxHeightDistance = profile.MaxHeightDistance; } private readonly LayerMask validLayers; private readonly LayerMask invalidLayers; private readonly float upDirectionThreshold; private readonly float maxDistanceSquare; + private readonly float maxHeightDistance; /// public TeleportValidationResult IsValid(IPointerResult pointerResult, IMixedRealityTeleportHotSpot teleportHotSpot = null) @@ -36,7 +38,8 @@ public TeleportValidationResult IsValid(IPointerResult pointerResult, IMixedReal TeleportValidationResult teleportValidationResult; // Check distance. - if ((pointerResult.EndPoint - CameraCache.Main.transform.position).sqrMagnitude > maxDistanceSquare) + if ((pointerResult.EndPoint - CameraCache.Main.transform.position).sqrMagnitude > maxDistanceSquare || + Mathf.Abs(pointerResult.EndPoint.y - CameraCache.Main.transform.position.y) > maxHeightDistance) { teleportValidationResult = TeleportValidationResult.Invalid; }