Skip to content

Commit 595ae63

Browse files
Merge branch 'vNEXT-CursorTest' into vNEXT-SpatialMouse
2 parents 5b09763 + c0539d6 commit 595ae63

File tree

6 files changed

+85
-11
lines changed

6 files changed

+85
-11
lines changed

Assets/MixedRealityToolkit-SDK/Features/Input/GazeProvider.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
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 Microsoft.MixedReality.Toolkit.InputSystem.Pointers;
5-
using Microsoft.MixedReality.Toolkit.InputSystem.Sources;
64
using Microsoft.MixedReality.Toolkit.Core.Definitions.InputSystem;
75
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
86
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
97
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Devices;
108
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
119
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem.Handlers;
1210
using Microsoft.MixedReality.Toolkit.Core.Utilities;
11+
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
1312
using Microsoft.MixedReality.Toolkit.Core.Utilities.Physics;
13+
using Microsoft.MixedReality.Toolkit.InputSystem.Pointers;
14+
using Microsoft.MixedReality.Toolkit.InputSystem.Sources;
1415
using UnityEngine;
1516

1617
namespace Microsoft.MixedReality.Toolkit.SDK.Input
@@ -268,8 +269,10 @@ protected override void OnEnable()
268269
}
269270
}
270271

271-
protected virtual void Start()
272+
protected override void Start()
272273
{
274+
base.Start();
275+
273276
if (cursorPrefab != null)
274277
{
275278
var cursorObj = Instantiate(cursorPrefab, transform.parent);
@@ -335,7 +338,7 @@ protected override void OnDisable()
335338
{
336339
base.OnDisable();
337340
GazePointer.BaseCursor?.SetVisibility(false);
338-
InputSystem.RaiseSourceLost(GazeInputSource);
341+
InputSystem?.RaiseSourceLost(GazeInputSource);
339342
}
340343

341344
#endregion MonoBehaviour Implementation
@@ -385,8 +388,9 @@ private IMixedRealityPointer InitializeGazePointer()
385388
return gazePointer = new InternalGazePointer(this, "Gaze Pointer", null, raycastLayerMasks, maxGazeCollisionDistance, gazeTransform, stabilizer);
386389
}
387390

388-
private void RaiseSourceDetected()
391+
private async void RaiseSourceDetected()
389392
{
393+
await WaitUntilInputSystemValid;
390394
InputSystem.RaiseSourceDetected(GazeInputSource);
391395
GazePointer.BaseCursor?.SetVisibility(true);
392396
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public class SpeechInputHandler : BaseInputHandler, IMixedRealitySpeechHandler
3333

3434
#region MonoBehaviour Implementation
3535

36-
private void Start()
36+
protected override void Start()
3737
{
38+
base.Start();
39+
3840
if (persistentKeywords)
3941
{
4042
Debug.Assert(gameObject.transform.parent == null, "Persistent keyword GameObject must be at the root level of the scene hierarchy.");

Assets/MixedRealityToolkit-SDK/Features/Input/InputSystemGlobalListener.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
55
using Microsoft.MixedReality.Toolkit.Core.Managers;
6+
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
67
using UnityEngine;
78

89
namespace Microsoft.MixedReality.Toolkit.SDK.Input
@@ -15,16 +16,31 @@ public class InputSystemGlobalListener : MonoBehaviour
1516
private static IMixedRealityInputSystem inputSystem = null;
1617
protected static IMixedRealityInputSystem InputSystem => inputSystem ?? (inputSystem = MixedRealityManager.Instance.GetManager<IMixedRealityInputSystem>());
1718

19+
private bool lateInitialize = true;
20+
21+
protected readonly WaitUntil WaitUntilInputSystemValid = new WaitUntil(() => InputSystem != null);
22+
1823
protected virtual void OnEnable()
1924
{
20-
Debug.Assert(MixedRealityManager.IsInitialized, "No Mixed Reality Manager found in the scene. Be sure to run the Mixed Reality Configuration.");
21-
Debug.Assert(InputSystem != null, "No Input System found, Did you set it up in your configuration profile?");
22-
InputSystem.Register(gameObject);
25+
if (MixedRealityManager.IsInitialized && InputSystem != null && !lateInitialize)
26+
{
27+
InputSystem.Register(gameObject);
28+
}
29+
}
30+
31+
protected virtual async void Start()
32+
{
33+
if (lateInitialize)
34+
{
35+
await WaitUntilInputSystemValid;
36+
lateInitialize = false;
37+
InputSystem.Register(gameObject);
38+
}
2339
}
2440

2541
protected virtual void OnDisable()
2642
{
27-
InputSystem.Unregister(gameObject);
43+
InputSystem?.Unregister(gameObject);
2844
}
2945
}
3046
}

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Cursors/BaseCursor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ protected virtual void UpdateCursorTransform()
316316
{
317317
Debug.LogError($"{name}: Unable to get focus details for {pointer.GetType().Name}!");
318318
}
319+
else if (pointer.GetType() != typeof(TouchPointer))
320+
{
321+
Debug.LogWarning($"{pointer.GetType().Name} not registered!");
322+
}
319323

320324
return;
321325
}

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Pointers/BaseControllerPointer.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public abstract class BaseControllerPointer : ControllerPoseSynchronizer, IMixed
6161

6262
protected bool IsTeleportRequestActive = false;
6363

64+
private bool lateRegisterTeleport = false;
65+
6466
/// <summary>
6567
/// The forward direction of the targeting ray
6668
/// </summary>
@@ -116,7 +118,33 @@ protected override void OnEnable()
116118
base.OnEnable();
117119
SetCursor();
118120
BaseCursor?.SetVisibility(true);
119-
TeleportSystem?.Register(gameObject);
121+
122+
if (TeleportSystem == null)
123+
{
124+
lateRegisterTeleport = true;
125+
}
126+
else if (!lateRegisterTeleport)
127+
{
128+
TeleportSystem.Register(gameObject);
129+
}
130+
}
131+
132+
protected override void Start()
133+
{
134+
base.Start();
135+
136+
if (lateRegisterTeleport)
137+
{
138+
if (TeleportSystem == null)
139+
{
140+
Debug.LogError("Failed to find the Teleport System!");
141+
}
142+
else
143+
{
144+
lateRegisterTeleport = false;
145+
TeleportSystem.Register(gameObject);
146+
}
147+
}
120148
}
121149

122150
protected override void OnDisable()

Assets/MixedRealityToolkit-SDK/Features/UX/Scripts/Pointers/MousePointer.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ public override void OnPositionInputChanged(InputEventData<Vector2> eventData)
9393
}
9494
}
9595

96+
protected override void Start()
97+
{
98+
base.Start();
99+
100+
if (RayStabilizer != null)
101+
{
102+
RayStabilizer = null;
103+
}
104+
105+
foreach (var inputSource in InputSystem.DetectedInputSources)
106+
{
107+
if (inputSource.SourceId == Controller.InputSource.SourceId)
108+
{
109+
isInteractionEnabled = true;
110+
break;
111+
}
112+
}
113+
}
114+
96115
/// <inheritdoc />
97116
public override void OnSourceDetected(SourceStateEventData eventData)
98117
{
@@ -105,6 +124,7 @@ public override void OnSourceDetected(SourceStateEventData eventData)
105124

106125
if (eventData.InputSource.SourceId == Controller.InputSource.SourceId)
107126
{
127+
Debug.Log("Pointer detected");
108128
isInteractionEnabled = true;
109129
}
110130
}

0 commit comments

Comments
 (0)