Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Teleport System v2 (#722)
Browse files Browse the repository at this point in the history
* Define teleport system profile

* Add profile inspector definition

* Register system with new profile properly

* Fix teleportation

* Introduce concept of teleport handler

* Implement MixedRealityTeleportSystem v2

* Update submodules
  • Loading branch information
FejZa authored Dec 18, 2020
1 parent 47ec073 commit 99e939b
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 93 deletions.
35 changes: 35 additions & 0 deletions Editor/Profiles/MixedRealityTeleportSystemProfileInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEditor;
using XRTK.Definitions.TeleportSystem;

namespace XRTK.Editor.Profiles
{
[CustomEditor(typeof(MixedRealityTeleportSystemProfile))]
public class MixedRealityTeleportSystemProfileInspector : MixedRealityServiceProfileInspector
{
private SerializedProperty teleportHandlerComponent;

protected override void OnEnable()
{
base.OnEnable();

teleportHandlerComponent = serializedObject.FindProperty(nameof(teleportHandlerComponent));
}

public override void OnInspectorGUI()
{
RenderHeader("The teleport system profile defines default behaviour for the teleport system.");

serializedObject.Update();

EditorGUILayout.PropertyField(teleportHandlerComponent);

EditorGUILayout.Space();
base.OnInspectorGUI();

serializedObject.ApplyModifiedProperties();
}
}
}
11 changes: 11 additions & 0 deletions Editor/Profiles/MixedRealityTeleportSystemProfileInspector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Editor/Profiles/MixedRealityToolkitRootProfileInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MixedRealityToolkitRootProfileInspector : BaseMixedRealityProfileIn
// Teleport system properties
private SerializedProperty enableTeleportSystem;
private SerializedProperty teleportSystemType;
private SerializedProperty teleportSystemProfile;

// Spatial Awareness system properties
private SerializedProperty enableSpatialAwarenessSystem;
Expand Down Expand Up @@ -161,6 +162,7 @@ protected override void OnEnable()
// Teleport system configuration
enableTeleportSystem = serializedObject.FindProperty(nameof(enableTeleportSystem));
teleportSystemType = serializedObject.FindProperty(nameof(teleportSystemType));
teleportSystemProfile = serializedObject.FindProperty(nameof(teleportSystemProfile));

// Spatial Awareness system configuration
enableSpatialAwarenessSystem = serializedObject.FindProperty(nameof(enableSpatialAwarenessSystem));
Expand Down Expand Up @@ -231,6 +233,8 @@ internal void RenderSystemFields()
EditorGUI.indentLevel++;
typeLabel.tooltip = teleportSystemType.tooltip;
EditorGUILayout.PropertyField(teleportSystemType, typeLabel);
profileLabel.tooltip = teleportSystemProfile.tooltip;
EditorGUILayout.PropertyField(teleportSystemProfile, profileLabel);
EditorGUI.indentLevel--;

// Spatial Awareness System configuration
Expand Down
14 changes: 14 additions & 0 deletions Runtime/Definitions/MixedRealityToolkitRootProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.NetworkingSystem;
using XRTK.Definitions.SpatialAwarenessSystem;
using XRTK.Definitions.TeleportSystem;
using XRTK.Definitions.Utilities;
using XRTK.Interfaces.BoundarySystem;
using XRTK.Interfaces.CameraSystem;
Expand Down Expand Up @@ -189,6 +190,19 @@ public SystemType TeleportSystemSystemType
internal set => teleportSystemType = value;
}

[SerializeField]
[Tooltip("Profile for configuring the teleport system.")]
private MixedRealityTeleportSystemProfile teleportSystemProfile;

/// <summary>
/// Active profile for teleport configuration.
/// </summary>
public MixedRealityTeleportSystemProfile TeleportSystemProfile
{
get => teleportSystemProfile;
internal set => teleportSystemProfile = value;
}

#endregion Teleportation System Properties

#region Spatial Awareness System Properties
Expand Down
8 changes: 8 additions & 0 deletions Runtime/Definitions/TeleportSystem.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using XRTK.Attributes;
using XRTK.Definitions.Utilities;
using XRTK.Interfaces.TeleportSystem;
using XRTK.Interfaces.TeleportSystem.Handlers;

namespace XRTK.Definitions.TeleportSystem
{
/// <summary>
/// Configuration profile for the <see cref="Services.Teleportation.MixedRealityTeleportSystem"/>.
/// </summary>
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Teleport System Profile", fileName = "MixedRealityTeleportSystemProfile", order = (int)CreateProfileMenuItemIndices.Input)]
public class MixedRealityTeleportSystemProfile : BaseMixedRealityServiceProfile<IMixedRealityTeleportDataProvider>
{
[SerializeField]
[Implements(typeof(IMixedRealityTeleportComponentHandler), TypeGrouping.ByNamespaceFlat)]
[Tooltip("The concrete teleport handler component to use for teleportation.")]
private SystemType teleportHandlerComponent = null;

/// <summary>
/// The concrete teleport handler component to use for teleportation.
/// </summary>
public SystemType TeleportHandlerComponent => teleportHandlerComponent;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace XRTK.Interfaces.TeleportSystem.Handlers
{
/// <summary>
/// Interface to implement for handling teleport events by the <see cref="IMixedRealityTeleportSystem"/>
/// in <see cref="UnityEngine.MonoBehaviour"/> components.
/// </summary>
public interface IMixedRealityTeleportComponentHandler : IMixedRealityTeleportHandler { }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
using UnityEngine.EventSystems;
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine.EventSystems;
using XRTK.EventDatum.Teleport;

namespace XRTK.Interfaces.TeleportSystem
namespace XRTK.Interfaces.TeleportSystem.Handlers
{
/// <summary>
/// Interface to implement for teleport events.
/// Interface to implement for handling teleport events by the <see cref="IMixedRealityTeleportSystem"/>.
/// </summary>
public interface IMixedRealityTeleportHandler : IEventSystemHandler
{
/// <summary>
/// Raised when a pointer requests a teleport target, but no teleport has begun.
/// </summary>
/// <param name="eventData"></param>
/// <param name="eventData">Teleport event data.</param>
void OnTeleportRequest(TeleportEventData eventData);

/// <summary>
/// Raised when a teleport has started.
/// </summary>
/// <param name="eventData"></param>
/// <param name="eventData">Teleport event data.</param>
void OnTeleportStarted(TeleportEventData eventData);

/// <summary>
/// Raised when a teleport has successfully completed.
/// </summary>
/// <param name="eventData"></param>
/// <param name="eventData">Teleport event data.</param>
void OnTeleportCompleted(TeleportEventData eventData);

/// <summary>
/// Raised when a teleport request has been canceled.
/// </summary>
/// <param name="eventData"></param>
/// <param name="eventData">Teleport event data.</param>
void OnTeleportCanceled(TeleportEventData eventData);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

namespace XRTK.Interfaces.TeleportSystem
{
/// <summary>
/// The base interface to define teleportation data providers.
/// </summary>
public interface IMixedRealityTeleportDataProvider : IMixedRealityDataProvider { }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions Runtime/Interfaces/TeleportSystem/IMixedRealityTeleportSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) XRTK. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using XRTK.Interfaces.Events;
Expand All @@ -7,16 +7,11 @@
namespace XRTK.Interfaces.TeleportSystem
{
/// <summary>
/// Manager interface for a Teleport system in the Mixed Reality Toolkit
/// All replacement systems for providing Teleportation functionality should derive from this interface
/// Manager interface for a Teleport system in the Mixed Reality Toolkit.
/// All replacement systems for providing Teleportation functionality should derive from this interface.
/// </summary>
public interface IMixedRealityTeleportSystem : IMixedRealityEventSystem
{
/// <summary>
/// The duration of the teleport in seconds.
/// </summary>
float TeleportDuration { get; set; }

/// <summary>
/// Raise a teleportation request event.
/// </summary>
Expand All @@ -31,6 +26,13 @@ public interface IMixedRealityTeleportSystem : IMixedRealityEventSystem
/// <param name="hotSpot">The teleport target</param>
void RaiseTeleportStarted(IMixedRealityPointer pointer, IMixedRealityTeleportHotSpot hotSpot);

/// <summary>
/// Raise a teleportation completed event.
/// </summary>
/// <param name="pointer">The pointer that raised the event.</param>
/// <param name="hotSpot">The teleport target</param>
void RaiseTeleportComplete(IMixedRealityPointer pointer, IMixedRealityTeleportHotSpot hotSpot);

/// <summary>
/// Raise a teleportation canceled event.
/// </summary>
Expand Down
5 changes: 1 addition & 4 deletions Runtime/Services/MixedRealityToolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,7 @@ private void InitializeServiceLocator()

if (ActiveProfile.IsTeleportSystemEnabled)
{
// Note: The Teleport system doesn't have a profile, but might in the future.
var dummyProfile = ScriptableObject.CreateInstance<MixedRealityToolkitRootProfile>();

if (!TryCreateAndRegisterService<IMixedRealityTeleportSystem>(ActiveProfile.TeleportSystemSystemType, out _, dummyProfile) || TeleportSystem == null)
if (!TryCreateAndRegisterService<IMixedRealityTeleportSystem>(ActiveProfile.TeleportSystemSystemType, out _, ActiveProfile.TeleportSystemProfile) || TeleportSystem == null)
{
Debug.LogError("Failed to start the Teleport System!");
}
Expand Down
Loading

0 comments on commit 99e939b

Please sign in to comment.