Skip to content

Commit

Permalink
Feature/721 teleport input action (#729)
Browse files Browse the repository at this point in the history
* Add teleport action to system profile

* Add TeleportAction to teleport system

* Implement additionl teleport constraint for height offset
  • Loading branch information
FejZa committed Dec 21, 2020
1 parent b681bf2 commit 1314dc5
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -27,6 +29,7 @@ public override void OnInspectorGUI()
EditorGUI.BeginChangeCheck();

EditorGUILayout.PropertyField(teleportProvider);
EditorGUILayout.PropertyField(teleportAction);

serializedObject.ApplyModifiedProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MixedRealityTeleportValidationDataProviderProfileInspector : BaseMi
private SerializedProperty invalidLayers;
private SerializedProperty upDirectionThreshold;
private SerializedProperty maxDistance;
private SerializedProperty maxHeightDistance;

protected override void OnEnable()
{
Expand All @@ -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()
Expand All @@ -34,6 +36,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(invalidLayers);
EditorGUILayout.PropertyField(upDirectionThreshold);
EditorGUILayout.PropertyField(maxDistance);
EditorGUILayout.PropertyField(maxHeightDistance);

serializedObject.ApplyModifiedProperties();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/// <summary>
/// Input action to trigger a teleport request.
/// </summary>
public MixedRealityInputAction TeleportAction
{
get => teleportAction;
internal set => teleportAction = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// The maximum height distance from the player a teleport location can be away.
/// </summary>
public float MaxHeightDistance
{
get => maxHeightDistance;
internal set => maxHeightDistance = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -12,6 +13,12 @@ namespace XRTK.Interfaces.TeleportSystem
/// </summary>
public interface IMixedRealityTeleportSystem : IMixedRealityEventSystem
{
/// <summary>
/// Gets the <see cref="MixedRealityInputAction"/> used to trigger a teleport
/// request.
/// </summary>
MixedRealityInputAction TeleportAction { get; }

/// <summary>
/// Raise a teleportation request event.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -125,6 +126,9 @@ public override void Unregister(GameObject listener)

#region IMixedRealityTeleportSystem Implementation

/// <inheritdoc />
public MixedRealityInputAction TeleportAction { get; private set; }

private static readonly ExecuteEvents.EventFunction<IMixedRealityTeleportHandler> OnTeleportRequestHandler =
delegate (IMixedRealityTeleportHandler handler, BaseEventData eventData)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@ 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;

/// <inheritdoc />
public TeleportValidationResult IsValid(IPointerResult pointerResult, IMixedRealityTeleportHotSpot teleportHotSpot = null)
{
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;
}
Expand Down

0 comments on commit 1314dc5

Please sign in to comment.