Skip to content

Commit fa69eb9

Browse files
authored
Merge pull request #2545 from StephenHodgson/vNEXT-Teleportation
vNEXT Teleportation Feature Port
2 parents 385e880 + fd00314 commit fa69eb9

File tree

85 files changed

+5433
-203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5433
-203
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/ControllerPoseSynchronizer.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ public bool DisableChildren
3838
set { disableChildren = value; }
3939
}
4040

41+
[SerializeField]
42+
[Tooltip("Should this GameObject clean itself up after source is lost?")]
43+
private bool destroyOnSourceLost = true;
44+
45+
/// <summary>
46+
/// Should this GameObject clean itself up after source is lost?
47+
/// </summary>
48+
public bool DestroyOnSourceLost
49+
{
50+
get { return destroyOnSourceLost; }
51+
set { destroyOnSourceLost = value; }
52+
}
53+
4154
/// <summary>
4255
/// Is the controller this Synchronizer is registered to currently tracked?
4356
/// </summary>
@@ -105,6 +118,18 @@ public virtual void OnSourceLost(SourceStateEventData eventData)
105118
{
106119
gameObject.SetChildrenActive(false);
107120
}
121+
122+
if (destroyOnSourceLost)
123+
{
124+
if (Application.isEditor)
125+
{
126+
DestroyImmediate(gameObject);
127+
}
128+
else
129+
{
130+
Destroy(gameObject);
131+
}
132+
}
108133
}
109134
}
110135

@@ -126,8 +151,8 @@ public virtual void OnSourcePoseChanged(SourcePoseEventData eventData)
126151

127152
if (TrackingState == TrackingState.Tracked)
128153
{
129-
transform.position = eventData.MixedRealityPose.Position;
130-
transform.rotation = eventData.MixedRealityPose.Rotation;
154+
transform.localPosition = eventData.MixedRealityPose.Position;
155+
transform.localRotation = eventData.MixedRealityPose.Rotation;
131156
}
132157
}
133158

Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/TeleportHandler.cs renamed to Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/TeleportHotSpot.cs

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,55 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using Microsoft.MixedReality.Toolkit.Internal.EventDatum.Input;
5-
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.InputSystem;
5+
using Microsoft.MixedReality.Toolkit.Internal.Interfaces.TeleportSystem;
6+
using Microsoft.MixedReality.Toolkit.Internal.Managers;
7+
using Microsoft.MixedReality.Toolkit.SDK.UX.Pointers;
68
using UnityEngine;
79

810
namespace Microsoft.MixedReality.Toolkit.SDK.Input.Handlers
911
{
1012
/// <summary>
11-
/// SDK component handling teleportation when a user focuses this <see cref="GameObject"/> and triggers the teleport action.
13+
/// SDK component handling teleportation to a specific position &amp; orientation when a user focuses
14+
/// this <see cref="GameObject"/> and triggers the teleport action.
1215
/// </summary>
13-
public class TeleportHandler : BaseFocusHandler, ITeleportTarget
16+
public class TeleportHotSpot : BaseFocusHandler, IMixedRealityTeleportHotSpot
1417
{
15-
[SerializeField]
16-
[Tooltip("Should the destination orientation be overridden? " +
17-
"Useful when you want to orient the user in a specific direction when they teleport to this position. " +
18-
"Override orientation is the transform forward of the GameObject this component is attached to.")]
19-
private bool overrideOrientation = false;
18+
private static IMixedRealityTeleportSystem teleportSystem = null;
19+
protected static IMixedRealityTeleportSystem TeleportSystem => teleportSystem ?? (teleportSystem = MixedRealityManager.Instance.GetManager<IMixedRealityTeleportSystem>());
20+
21+
#region IMixedRealityFocusHandler Implementation
22+
23+
/// <inheritdoc />
24+
public override void OnBeforeFocusChange(FocusEventData eventData)
25+
{
26+
base.OnBeforeFocusChange(eventData);
27+
28+
if (!(eventData.Pointer is TeleportPointer)) { return; }
29+
30+
if (eventData.NewFocusedObject == gameObject)
31+
{
32+
eventData.Pointer.TeleportHotSpot = this;
33+
34+
if (eventData.Pointer.IsInteractionEnabled)
35+
{
36+
TeleportSystem.RaiseTeleportCanceled(eventData.Pointer, this);
37+
TeleportSystem.RaiseTeleportRequest(eventData.Pointer, this);
38+
}
39+
}
40+
else if (eventData.OldFocusedObject == gameObject)
41+
{
42+
eventData.Pointer.TeleportHotSpot = null;
43+
44+
if (eventData.Pointer.IsInteractionEnabled)
45+
{
46+
TeleportSystem.RaiseTeleportCanceled(eventData.Pointer, this);
47+
}
48+
}
49+
}
50+
51+
#endregion IMixedRealityFocusHandler Implementation
52+
53+
#region IMixedRealityTeleportTarget Implementation
2054

2155
/// <inheritdoc />
2256
public Vector3 Position => transform.position;
@@ -27,27 +61,22 @@ public class TeleportHandler : BaseFocusHandler, ITeleportTarget
2761
/// <inheritdoc />
2862
public bool IsActive => isActiveAndEnabled;
2963

64+
[SerializeField]
65+
[Tooltip("Should the destination orientation be overridden? " +
66+
"Useful when you want to orient the user in a specific direction when they teleport to this position. " +
67+
"Override orientation is the transform forward of the GameObject this component is attached to.")]
68+
private bool overrideOrientation = false;
69+
3070
/// <inheritdoc />
3171
public bool OverrideTargetOrientation => overrideOrientation;
3272

3373
/// <inheritdoc />
3474
public float TargetOrientation => transform.eulerAngles.y;
3575

3676
/// <inheritdoc />
37-
public override void OnBeforeFocusChange(FocusEventData eventData)
38-
{
39-
base.OnBeforeFocusChange(eventData);
77+
public GameObject GameObjectReference => gameObject;
4078

41-
if (eventData.NewFocusedObject == gameObject)
42-
{
43-
eventData.Pointer.TeleportTarget = this;
44-
}
45-
46-
if (eventData.OldFocusedObject == gameObject)
47-
{
48-
eventData.Pointer.TeleportTarget = null;
49-
}
50-
}
79+
#endregion IMixedRealityTeleportTarget Implementation
5180

5281
private void OnDrawGizmos()
5382
{

Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/TeleportHandler.cs.meta renamed to Assets/MixedRealityToolkit-SDK/Features/Input/Handlers/TeleportHotSpot.cs.meta

File renamed without changes.

Assets/MixedRealityToolkit-SDK/Features/Teleportation.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)