Skip to content

Commit d591e23

Browse files
committed
Adding support for two motion controllers, and reverting to use the Toolkit's InputManager
1 parent 2c95976 commit d591e23

File tree

3 files changed

+92
-87
lines changed

3 files changed

+92
-87
lines changed

Assets/HoloToolkit/Input/Prefabs/MixedRealityCameraParent.prefab

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ GameObject:
232232
serializedVersion: 5
233233
m_Component:
234234
- component: {fileID: 4541142303025740}
235-
- component: {fileID: 114092548863884916}
235+
- component: {fileID: 114059824862712730}
236+
- component: {fileID: 114812681035175298}
236237
m_Layer: 0
237238
m_Name: MixedRealityCameraParent
238239
m_TagString: Untagged
@@ -599,6 +600,17 @@ MonoBehaviour:
599600
Axis0Destination: 0
600601
Axis1Destination: 4
601602
Axis2Destination: 6
603+
--- !u!114 &114059824862712730
604+
MonoBehaviour:
605+
m_ObjectHideFlags: 1
606+
m_PrefabParentObject: {fileID: 0}
607+
m_PrefabInternal: {fileID: 100100000}
608+
m_GameObject: {fileID: 1850730992894404}
609+
m_Enabled: 1
610+
m_EditorHideFlags: 0
611+
m_Script: {fileID: 11500000, guid: cae8f3c88e9704a4393cb8d904b62372, type: 3}
612+
m_Name:
613+
m_EditorClassIdentifier:
602614
--- !u!114 &114061490341948574
603615
MonoBehaviour:
604616
m_ObjectHideFlags: 1
@@ -623,26 +635,6 @@ MonoBehaviour:
623635
JoystickXYRotationAxisControl: {fileID: 114991520948515094}
624636
JoystickXYTranslationAxisControl: {fileID: 114873870855691164}
625637
JoystickXZTranslationAxisControl: {fileID: 114029515443702222}
626-
--- !u!114 &114092548863884916
627-
MonoBehaviour:
628-
m_ObjectHideFlags: 1
629-
m_PrefabParentObject: {fileID: 0}
630-
m_PrefabInternal: {fileID: 100100000}
631-
m_GameObject: {fileID: 1850730992894404}
632-
m_Enabled: 1
633-
m_EditorHideFlags: 0
634-
m_Script: {fileID: 11500000, guid: 1bc175d33f66e6647aabac1b65e7e632, type: 3}
635-
m_Name:
636-
m_EditorClassIdentifier:
637-
TeleportButtonName: Jump
638-
GoBackButtonName: Fire2
639-
LeftJoystickX: ControllerLeftStickX
640-
LeftJoystickY: ControllerLeftStickY
641-
EnableTeleport: 1
642-
EnableJoystickMovement: 0
643-
BumperRotationSize: 30
644-
TeleportMarker: {fileID: 1503526479864244, guid: 10d95b99055c6ad40b735cc8b3593745,
645-
type: 2}
646638
--- !u!114 &114121188885475510
647639
MonoBehaviour:
648640
m_ObjectHideFlags: 1
@@ -801,6 +793,27 @@ MonoBehaviour:
801793
Axis0Destination: 4
802794
Axis1Destination: 6
803795
Axis2Destination: 6
796+
--- !u!114 &114812681035175298
797+
MonoBehaviour:
798+
m_ObjectHideFlags: 1
799+
m_PrefabParentObject: {fileID: 0}
800+
m_PrefabInternal: {fileID: 100100000}
801+
m_GameObject: {fileID: 1850730992894404}
802+
m_Enabled: 1
803+
m_EditorHideFlags: 0
804+
m_Script: {fileID: 11500000, guid: 1bc175d33f66e6647aabac1b65e7e632, type: 3}
805+
m_Name:
806+
m_EditorClassIdentifier:
807+
LeftJoystickX: ControllerLeftStickX
808+
LeftJoystickY: ControllerLeftStickY
809+
EnableTeleport: 1
810+
EnableRotation: 1
811+
EnableStrafe: 1
812+
EnableJoystickMovement: 0
813+
RotationSize: 45
814+
StrafeAmount: 0.5
815+
TeleportMarker: {fileID: 1503526479864244, guid: 10d95b99055c6ad40b735cc8b3593745,
816+
type: 2}
804817
--- !u!114 &114828096048444974
805818
MonoBehaviour:
806819
m_ObjectHideFlags: 1

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,24 @@ public GameObject TryGetFocusedObject(BaseEventData eventData)
263263
{
264264
FocusDetails? details = TryGetFocusDetails(eventData);
265265

266-
return (details == null)
267-
? null
268-
: details.Value.Object;
266+
return (details == null) ? null : details.Value.Object;
267+
}
268+
269+
public bool TryGetPointingSource(BaseEventData eventData, out IPointingSource pointingSource)
270+
{
271+
for (int iPointer = 0; iPointer < pointers.Count; iPointer++)
272+
{
273+
PointerData pointer = pointers[iPointer];
274+
275+
if (pointer.PointingSource.OwnsInput(eventData))
276+
{
277+
pointingSource = pointer.PointingSource;
278+
return true;
279+
}
280+
}
281+
282+
pointingSource = null;
283+
return false;
269284
}
270285

271286
public FocusDetails GetFocusDetails(IPointingSource pointingSource)
@@ -315,7 +330,7 @@ public PointerInputEventData BorrowPointerEventData()
315330
{
316331
Clear(uiRaycastPointerInputData);
317332
}
318-
333+
319334
return uiRaycastPointerInputData;
320335
}
321336

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

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace HoloToolkit.Unity.InputModule
1111
/// <summary>
1212
/// Script teleports the user to the location being gazed at when Y was pressed on a Gamepad.
1313
/// </summary>
14-
public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
14+
[RequireComponent(typeof(SetGlobalListener))]
15+
public class MixedRealityTeleport : Singleton<MixedRealityTeleport>, IControllerInputHandler
1516
{
1617
[Tooltip("Name of the joystick axis to move along X.")]
1718
public string LeftJoystickX = "ControllerLeftStickX";
@@ -23,10 +24,6 @@ public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
2324
public bool EnableRotation = true;
2425
public bool EnableStrafe = true;
2526

26-
public bool EnableJoystickMovement = false;
27-
28-
public float SpeedScale { get; set; }
29-
3027
public float RotationSize = 45.0f;
3128
public float StrafeAmount = 0.5f;
3229

@@ -39,11 +36,10 @@ public class MixedRealityTeleport : Singleton<MixedRealityTeleport>
3936
/// </summary>
4037
private FadeScript fadeControl;
4138

42-
private GazeManager gazeManager;
43-
private Vector3 positionBeforeJump = Vector3.zero;
4439
private GameObject teleportMarker;
45-
private bool teleportValid;
46-
private bool teleporting;
40+
private bool isTeleportValid;
41+
private IPointingSource currentPointingSource;
42+
private uint currentSourceId;
4743

4844
private void Start()
4945
{
@@ -53,11 +49,7 @@ private void Start()
5349
return;
5450
}
5551

56-
InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated;
57-
58-
gazeManager = GazeManager.Instance;
5952
fadeControl = FadeScript.Instance;
60-
SpeedScale = 0.6f;
6153

6254
teleportMarker = Instantiate(TeleportMarker);
6355
teleportMarker.SetActive(false);
@@ -76,7 +68,7 @@ void Update()
7668
HandleGamepad();
7769
}
7870

79-
if (teleporting)
71+
if (currentPointingSource != null)
8072
{
8173
PositionMarker();
8274
}
@@ -89,17 +81,20 @@ private void HandleGamepad()
8981
float leftX = Input.GetAxis("ControllerLeftStickX");
9082
float leftY = Input.GetAxis("ControllerLeftStickY");
9183

92-
if (!teleporting && leftY > 0.8 && Math.Abs(leftX) < 0.2)
84+
if (currentPointingSource == null && leftY > 0.8 && Math.Abs(leftX) < 0.2)
9385
{
94-
StartTeleport();
86+
if (FocusManager.Instance.TryGetSinglePointer(out currentPointingSource))
87+
{
88+
StartTeleport();
89+
}
9590
}
96-
else if (teleporting && Math.Sqrt(Math.Pow(leftX, 2) + Math.Pow(leftY, 2)) < 0.1)
91+
else if (currentPointingSource != null && Math.Sqrt(Math.Pow(leftX, 2) + Math.Pow(leftY, 2)) < 0.1)
9792
{
9893
FinishTeleport();
9994
}
10095
}
10196

102-
if (EnableStrafe && !teleporting && !fadeControl.Busy)
97+
if (EnableStrafe && currentPointingSource == null && !fadeControl.Busy)
10398
{
10499
float leftX = Input.GetAxis("ControllerLeftStickX");
105100
float leftY = Input.GetAxis("ControllerLeftStickY");
@@ -118,7 +113,7 @@ private void HandleGamepad()
118113
}
119114
}
120115

121-
if (EnableRotation && !teleporting && !fadeControl.Busy)
116+
if (EnableRotation && currentPointingSource == null && !fadeControl.Busy)
122117
{
123118
float rightX = Input.GetAxis("ControllerRightStickX");
124119
float rightY = Input.GetAxis("ControllerRightStickY");
@@ -133,36 +128,40 @@ private void HandleGamepad()
133128
}
134129
}
135130
}
136-
137-
private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
131+
132+
void IControllerInputHandler.OnInputPositionChanged(InputPositionEventData eventData)
138133
{
139134
if (EnableTeleport)
140135
{
141-
if (!teleporting && obj.state.thumbstickPosition.y > 0.8 && Math.Abs(obj.state.thumbstickPosition.x) < 0.2)
136+
if (currentPointingSource == null && eventData.Position.y > 0.8 && Math.Abs(eventData.Position.x) < 0.2)
142137
{
143-
StartTeleport();
138+
if (FocusManager.Instance.TryGetPointingSource(eventData, out currentPointingSource))
139+
{
140+
currentSourceId = eventData.SourceId;
141+
StartTeleport();
142+
}
144143
}
145-
else if (teleporting && obj.state.thumbstickPosition.magnitude < 0.1)
144+
else if (currentPointingSource != null && currentSourceId == eventData.SourceId && eventData.Position.magnitude < 0.1)
146145
{
147146
FinishTeleport();
148147
}
149148
}
150149

151-
if (EnableStrafe && !teleporting && !fadeControl.Busy)
150+
if (EnableStrafe && currentPointingSource == null)
152151
{
153-
if (obj.state.thumbstickPosition.y < -0.8 && Math.Abs(obj.state.thumbstickPosition.x) < 0.2)
152+
if (eventData.Position.y < -0.8 && Math.Abs(eventData.Position.x) < 0.2)
154153
{
155154
DoStrafe(Vector3.back * StrafeAmount);
156155
}
157156
}
158157

159-
if (EnableRotation && !teleporting && !fadeControl.Busy)
158+
if (EnableRotation && currentPointingSource == null)
160159
{
161-
if (obj.state.thumbstickPosition.x < -0.8 && Math.Abs(obj.state.thumbstickPosition.y) < 0.2)
160+
if (eventData.Position.x < -0.8 && Math.Abs(eventData.Position.y) < 0.2)
162161
{
163162
DoRotation(-RotationSize);
164163
}
165-
else if (obj.state.thumbstickPosition.x > 0.8 && Math.Abs(obj.state.thumbstickPosition.y) < 0.2)
164+
else if (eventData.Position.x > 0.8 && Math.Abs(eventData.Position.y) < 0.2)
166165
{
167166
DoRotation(RotationSize);
168167
}
@@ -171,21 +170,20 @@ private void InteractionManager_InteractionSourceUpdated(InteractionSourceUpdate
171170

172171
public void StartTeleport()
173172
{
174-
if (!teleporting && !fadeControl.Busy)
173+
if (currentPointingSource != null && !fadeControl.Busy)
175174
{
176-
teleporting = true;
177175
EnableMarker();
178176
PositionMarker();
179177
}
180178
}
181179

182180
private void FinishTeleport()
183181
{
184-
if (teleporting)
182+
if (currentPointingSource != null)
185183
{
186-
teleporting = false;
184+
currentPointingSource = null;
187185

188-
if (teleportValid)
186+
if (isTeleportValid)
189187
{
190188
RaycastHit hitInfo;
191189
Vector3 hitPos = teleportMarker.transform.position + Vector3.up * (Physics.Raycast(Camera.main.transform.position, Vector3.down, out hitInfo, 5.0f) ? hitInfo.distance : 2.6f);
@@ -263,41 +261,20 @@ private void DisableMarker()
263261

264262
private void PositionMarker()
265263
{
266-
Vector3 hitNormal = HitNormal();
267-
if (Vector3.Dot(hitNormal, Vector3.up) > 0.90f)
264+
FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(currentPointingSource);
265+
266+
if (focusDetails.Object != null && (Vector3.Dot(focusDetails.Normal, Vector3.up) > 0.90f))
268267
{
269-
teleportValid = true;
268+
isTeleportValid = true;
270269

271-
IPointingSource pointingSource;
272-
if (FocusManager.Instance.TryGetSinglePointer(out pointingSource))
273-
{
274-
teleportMarker.transform.position = FocusManager.Instance.GetFocusDetails(pointingSource).Point;
275-
}
270+
teleportMarker.transform.position = focusDetails.Point;
276271
}
277272
else
278273
{
279-
teleportValid = false;
280-
}
281-
282-
animationController.speed = teleportValid ? 1 : 0;
283-
}
284-
285-
private Vector3 HitNormal()
286-
{
287-
Vector3 retval = Vector3.zero;
288-
289-
IPointingSource pointingSource;
290-
if (FocusManager.Instance.TryGetSinglePointer(out pointingSource))
291-
{
292-
FocusDetails focusDetails = FocusManager.Instance.GetFocusDetails(pointingSource);
293-
294-
if (focusDetails.Object != null)
295-
{
296-
retval = focusDetails.Normal;
297-
}
274+
isTeleportValid = false;
298275
}
299276

300-
return retval;
277+
animationController.speed = isTeleportValid ? 1 : 0;
301278
}
302279
}
303280
}

0 commit comments

Comments
 (0)