Skip to content

Commit 7c960a6

Browse files
await until input system is valid
1 parent b45addf commit 7c960a6

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

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

Lines changed: 6 additions & 4 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
@@ -337,7 +338,7 @@ protected override void OnDisable()
337338
{
338339
base.OnDisable();
339340
GazePointer.BaseCursor?.SetVisibility(false);
340-
InputSystem.RaiseSourceLost(GazeInputSource);
341+
InputSystem?.RaiseSourceLost(GazeInputSource);
341342
}
342343

343344
#endregion MonoBehaviour Implementation
@@ -387,8 +388,9 @@ private IMixedRealityPointer InitializeGazePointer()
387388
return gazePointer = new InternalGazePointer(this, "Gaze Pointer", null, raycastLayerMasks, maxGazeCollisionDistance, gazeTransform, stabilizer);
388389
}
389390

390-
private void RaiseSourceDetected()
391+
private async void RaiseSourceDetected()
391392
{
393+
await WaitUntilInputSystemValid;
392394
InputSystem.RaiseSourceDetected(GazeInputSource);
393395
GazePointer.BaseCursor?.SetVisibility(true);
394396
}

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

Lines changed: 6 additions & 14 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
@@ -17,30 +18,21 @@ public class InputSystemGlobalListener : MonoBehaviour
1718

1819
private bool lateInitialize = true;
1920

21+
protected readonly WaitUntil WaitUntilInputSystemValid = new WaitUntil(() => InputSystem != null);
22+
2023
protected virtual void OnEnable()
2124
{
22-
if (!MixedRealityManager.IsInitialized)
23-
{
24-
Debug.LogError("Missing Mixed Reality Manager!");
25-
return;
26-
}
27-
28-
if (InputSystem != null && !lateInitialize)
25+
if (MixedRealityManager.IsInitialized && InputSystem != null && !lateInitialize)
2926
{
3027
InputSystem.Register(gameObject);
3128
}
3229
}
3330

34-
protected virtual void Start()
31+
protected virtual async void Start()
3532
{
3633
if (lateInitialize)
3734
{
38-
if (InputSystem == null)
39-
{
40-
Debug.LogError("Unable to find Input System!");
41-
return;
42-
}
43-
35+
await WaitUntilInputSystemValid;
4436
lateInitialize = false;
4537
InputSystem.Register(gameObject);
4638
}

0 commit comments

Comments
 (0)