Skip to content

Commit 2f18bc1

Browse files
committed
Initial work to migrate teleport to motion controllers
1 parent df56c90 commit 2f18bc1

File tree

5 files changed

+91
-87
lines changed

5 files changed

+91
-87
lines changed

Assets/HoloToolkit/Input/Scripts/Cursor/Cursor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ private void TryLoadPointerIfNeeded()
271271
{
272272
// For backward-compatibility, if a pointer wasn't specified, but there's exactly one
273273
// pointer currently registered with FocusManager, we use it.
274-
275-
Pointer = FocusManager.Instance.TryGetSinglePointer();
274+
IPointingSource pointingSource;
275+
if (FocusManager.Instance.TryGetSinglePointer(out pointingSource))
276+
{
277+
Pointer = pointingSource;
278+
}
276279
}
277280
else
278281
{

Assets/HoloToolkit/Input/Scripts/Focus/FocusManager.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,18 @@ public GameObject GetFocusedObject(IPointingSource pointingSource)
282282
/// Checks if exactly one pointer is registered and returns it if so.
283283
/// </summary>
284284
/// <returns>The registered pointer if exactly one is registered, null otherwise.</returns>
285-
public IPointingSource TryGetSinglePointer()
285+
public bool TryGetSinglePointer(out IPointingSource pointingSource)
286286
{
287-
IPointingSource singlePointer = (pointers.Count == 1)
288-
? pointers[0].PointingSource
289-
: null;
290-
291-
return singlePointer;
287+
if (pointers.Count == 1)
288+
{
289+
pointingSource = pointers[0].PointingSource;
290+
return true;
291+
}
292+
else
293+
{
294+
pointingSource = null;
295+
return false;
296+
}
292297
}
293298

294299
public delegate void FocusEnteredMethod(GameObject focusedObject);

Assets/HoloToolkit/Input/Scripts/Gaze/MixedRealityTeleport.cs

Lines changed: 71 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
using UnityEngine;
1+
using System;
2+
using UnityEngine;
23
using UnityEngine.XR.WSA.Input;
34

45
namespace HoloToolkit.Unity.InputModule
56
{
67
/// <summary>
78
/// Script teleports the user to the location being gazed at when Y was pressed on a Gamepad.
89
/// </summary>
9-
public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
10+
public class MixedRealityTeleport : Singleton<MixedRealityTeleport>, IControllerInputHandler
1011
{
11-
[Tooltip("Game pad button to press for teleporting or jump.")]
12-
public string TeleportButtonName = "Jump";
13-
14-
[Tooltip("Game pad button to press for going back to a state.")]
15-
public string GoBackButtonName = "Fire2";
16-
1712
[Tooltip("Name of the joystick axis to move along X.")]
1813
public string LeftJoystickX = "ControllerLeftStickX";
1914

@@ -26,7 +21,7 @@ public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
2621

2722
public float SpeedScale { get; set; }
2823

29-
public float BumperRotationSize = 30.0f;
24+
public float BumperRotationSize = 45.0f;
3025

3126
public GameObject TeleportMarker;
3227
private Animator animationController;
@@ -61,79 +56,13 @@ private void Start()
6156

6257
void Update()
6358
{
64-
HandleTeleport();
65-
HandleGoBackPressed();
6659
HandleJoystickMovement();
6760
if (InteractionManager.numSourceStates == 0)
6861
{
6962
HandleBumperRotation();
7063
}
7164
}
7265

73-
private void HandleTeleport()
74-
{
75-
if (EnableTeleport)
76-
{
77-
if (teleporting)
78-
{
79-
if (Input.GetButtonUp(TeleportButtonName))
80-
{
81-
teleporting = false;
82-
if (teleportValid)
83-
{
84-
positionBeforeJump = transform.position;
85-
float verticalOffset;
86-
RaycastHit hitInfo;
87-
if (Physics.Raycast(Camera.main.transform.position, Vector3.down, out hitInfo, 5.0f))
88-
{
89-
verticalOffset = hitInfo.distance;
90-
}
91-
else
92-
{
93-
verticalOffset = 2.6f;
94-
}
95-
96-
Vector3 hitPos = teleportMarker.transform.position + Vector3.up * verticalOffset;
97-
98-
fadeControl.DoFade(0.25f, 0.5f, () =>
99-
{
100-
SetWorldPosition(hitPos);
101-
}, null);
102-
}
103-
104-
DisableMarker();
105-
}
106-
else
107-
{
108-
PositionMarker();
109-
}
110-
}
111-
else
112-
{
113-
if (fadeControl.Busy == false && Input.GetButtonDown(TeleportButtonName))
114-
{
115-
teleporting = true;
116-
EnableMarker();
117-
PositionMarker();
118-
}
119-
}
120-
}
121-
}
122-
123-
private void HandleGoBackPressed()
124-
{
125-
if (EnableTeleport && Input.GetButtonDown(GoBackButtonName))
126-
{
127-
Vector3 oldPositionBeforeJump = positionBeforeJump;
128-
positionBeforeJump = transform.position;
129-
130-
fadeControl.DoFade(0.25f, 0.5f, () =>
131-
{
132-
SetWorldPosition(oldPositionBeforeJump);
133-
}, null);
134-
}
135-
}
136-
13766
private void HandleJoystickMovement()
13867
{
13968
if (EnableJoystickMovement)
@@ -221,7 +150,12 @@ private void PositionMarker()
221150
if (Vector3.Dot(hitNormal, Vector3.up) > 0.90f)
222151
{
223152
teleportValid = true;
224-
teleportMarker.transform.position = gazeManager.HitPosition;
153+
154+
IPointingSource pointingSource;
155+
if (FocusManager.Instance.TryGetSinglePointer(out pointingSource))
156+
{
157+
teleportMarker.transform.position = FocusManager.Instance.GetFocusDetails(pointingSource).Point;
158+
}
225159
}
226160
else
227161
{
@@ -234,11 +168,70 @@ private void PositionMarker()
234168
private Vector3 HitNormal()
235169
{
236170
Vector3 retval = Vector3.zero;
237-
if (gazeManager.HitObject != null)
171+
172+
IPointingSource pointingSource;
173+
if (FocusManager.Instance.TryGetSinglePointer(out pointingSource))
238174
{
239-
retval = gazeManager.HitNormal;
175+
FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(pointingSource);
176+
177+
if (focusDetails.Object != null)
178+
{
179+
retval = focusDetails.Normal;
180+
}
240181
}
182+
241183
return retval;
242184
}
185+
186+
void IControllerInputHandler.OnSelectPressedAmountChanged(SelectPressedEventData eventData)
187+
{
188+
}
189+
190+
void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData)
191+
{
192+
if(EnableTeleport)
193+
{
194+
if (fadeControl.Busy == false && teleporting == false && eventData.PressType == InteractionSourcePressType.Thumbstick && Math.Abs(1.0 - eventData.Position.y) < 0.2 && Math.Abs(eventData.Position.x) < 0.1)
195+
{
196+
teleporting = true;
197+
EnableMarker();
198+
PositionMarker();
199+
}
200+
else if (teleporting)
201+
{
202+
if (eventData.PressType == InteractionSourcePressType.Thumbstick && eventData.Position.magnitude < 0.1)
203+
{
204+
teleporting = false;
205+
if (teleportValid)
206+
{
207+
positionBeforeJump = transform.position;
208+
float verticalOffset;
209+
RaycastHit hitInfo;
210+
if (Physics.Raycast(Camera.main.transform.position, Vector3.down, out hitInfo, 5.0f))
211+
{
212+
verticalOffset = hitInfo.distance;
213+
}
214+
else
215+
{
216+
verticalOffset = 2.6f;
217+
}
218+
219+
Vector3 hitPos = teleportMarker.transform.position + Vector3.up * verticalOffset;
220+
221+
fadeControl.DoFade(0.25f, 0.5f, () =>
222+
{
223+
SetWorldPosition(hitPos);
224+
}, null);
225+
}
226+
227+
DisableMarker();
228+
}
229+
else
230+
{
231+
PositionMarker();
232+
}
233+
}
234+
}
235+
}
243236
}
244237
}

Assets/HoloToolkit/Input/Scripts/InputEvents/IControllerInputHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using UnityEngine.EventSystems;
5+
46
namespace HoloToolkit.Unity.InputModule
57
{
68
/// <summary>
79
/// Interface to implement to react to controller input changes.
810
/// </summary>
9-
public interface IControllerInputHandler : IInputHandler
11+
public interface IControllerInputHandler : IEventSystemHandler
1012
{
1113
void OnSelectPressedAmountChanged(SelectPressedEventData eventData);
1214
void OnInputPositionChanged(InputPositionEventData eventData);

Assets/HoloToolkit/Input/Scripts/InputSources/InteractionSourceInputSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void ResetUpdatedBooleans()
113113

114114
public uint SourceId { get { return Source.id; } }
115115
public InteractionSourceKind SourceKind { get { return Source.kind; } }
116+
public InteractionSourceHandedness Handedness { get { return Source.handedness; } }
116117
public readonly InteractionSource Source;
117118
public SourceCapability<Vector3> PointerPosition;
118119
public SourceCapability<Quaternion> PointerRotation;

0 commit comments

Comments
 (0)