Skip to content

Commit c3e7353

Browse files
author
David Kline
authored
Merge pull request #2824 from StephenHodgson/vNEXT-EasyManagerAccess
Centralized all the core manager accessors to MixedRealiyManager
2 parents f6175ab + 6cffe7f commit c3e7353

35 files changed

+267
-266
lines changed

Assets/MixedRealityToolkit-Examples/Demos/Boundary/Scripts/BoundaryVisualizationDemo.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.MixedReality.Toolkit.Core.Managers;
88
using Microsoft.MixedReality.Toolkit.Core.Utilities;
99
using System.Collections.Generic;
10+
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
1011
using UnityEngine;
1112
using UnityEngine.Experimental.XR;
1213

@@ -17,9 +18,6 @@ namespace Microsoft.MixedReality.Toolkit.Examples.Demos
1718
/// </summary>
1819
public class BoundaryVisualizationDemo : MonoBehaviour, IMixedRealityBoundaryHandler
1920
{
20-
private IMixedRealityBoundarySystem BoundaryManager => boundaryManager ?? (boundaryManager = MixedRealityManager.Instance.GetManager<IMixedRealityBoundarySystem>());
21-
private IMixedRealityBoundarySystem boundaryManager = null;
22-
2321
private GameObject markerParent;
2422
private readonly List<GameObject> markers = new List<GameObject>();
2523

@@ -50,7 +48,7 @@ private void Awake()
5048
private void Start()
5149
{
5250

53-
if (BoundaryManager != null)
51+
if (MixedRealityManager.BoundarySystem != null)
5452
{
5553
if (markers.Count == 0)
5654
{
@@ -61,24 +59,25 @@ private void Start()
6159

6260
private void Update()
6361
{
64-
if (BoundaryManager != null)
62+
if (MixedRealityManager.BoundarySystem != null)
6563
{
66-
BoundaryManager.ShowFloor = showFloor;
67-
BoundaryManager.ShowPlayArea = showPlayArea;
68-
BoundaryManager.ShowTrackedArea = showTrackedArea;
69-
BoundaryManager.ShowBoundaryWalls = showBoundaryWalls;
70-
BoundaryManager.ShowBoundaryCeiling = showBoundaryCeiling;
64+
MixedRealityManager.BoundarySystem.ShowFloor = showFloor;
65+
MixedRealityManager.BoundarySystem.ShowPlayArea = showPlayArea;
66+
MixedRealityManager.BoundarySystem.ShowTrackedArea = showTrackedArea;
67+
MixedRealityManager.BoundarySystem.ShowBoundaryWalls = showBoundaryWalls;
68+
MixedRealityManager.BoundarySystem.ShowBoundaryCeiling = showBoundaryCeiling;
7169
}
7270
}
7371

74-
private void OnEnable()
72+
private async void OnEnable()
7573
{
76-
BoundaryManager.Register(gameObject);
74+
await new WaitUntil(() => MixedRealityManager.BoundarySystem != null);
75+
MixedRealityManager.BoundarySystem.Register(gameObject);
7776
}
7877

7978
private void OnDisable()
8079
{
81-
BoundaryManager.Unregister(gameObject);
80+
MixedRealityManager.BoundarySystem?.Unregister(gameObject);
8281
}
8382

8483
#endregion MonoBehaviour Implementation
@@ -105,7 +104,7 @@ private void AddMarkers()
105104
float widthRect;
106105
float heightRect;
107106

108-
if (!BoundaryManager.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
107+
if (!MixedRealityManager.BoundarySystem.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
109108
{
110109
// If we have no boundary manager or rectangular bounds we will show no indicators
111110
return;
@@ -136,12 +135,12 @@ private void AddMarkers()
136135

137136
Material material = null;
138137
// Check inscribed rectangle first
139-
if (BoundaryManager.Contains(position, Boundary.Type.PlayArea))
138+
if (MixedRealityManager.BoundarySystem.Contains(position, Boundary.Type.PlayArea))
140139
{
141140
material = visualizationProfile.PlayAreaMaterial;
142141
}
143142
// Then check geometry
144-
else if (BoundaryManager.Contains(position, Boundary.Type.TrackedArea))
143+
else if (MixedRealityManager.BoundarySystem.Contains(position, Boundary.Type.TrackedArea))
145144
{
146145
material = visualizationProfile.TrackedAreaMaterial;
147146
}

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
66
using Microsoft.MixedReality.Toolkit.Core.Extensions;
77
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
8+
using Microsoft.MixedReality.Toolkit.Core.Managers;
89
using Microsoft.MixedReality.Toolkit.Core.Utilities;
10+
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
911
using Microsoft.MixedReality.Toolkit.Core.Utilities.Physics;
1012
using System;
1113
using System.Collections.Generic;
@@ -223,7 +225,7 @@ public override int GetHashCode()
223225

224226
#region MonoBehaviour Implementation
225227

226-
private void Awake()
228+
private async void Awake()
227229
{
228230
if (uiRaycastCamera == null)
229231
{
@@ -232,14 +234,18 @@ private void Awake()
232234
CreateUiRaycastCamera();
233235
}
234236

235-
foreach (var inputSource in InputSystem.DetectedInputSources)
237+
await WaitUntilInputSystemValid;
238+
239+
foreach (var inputSource in MixedRealityManager.InputSystem.DetectedInputSources)
236240
{
237241
RegisterPointers(inputSource);
238242
}
239243
}
240244

241245
private void Update()
242246
{
247+
if (MixedRealityManager.InputSystem == null) { return; }
248+
243249
UpdatePointers();
244250
UpdateFocusedObjects();
245251
}
@@ -447,7 +453,7 @@ private void RegisterPointers(IMixedRealityInputSource inputSource)
447453
RegisterPointer(inputSource.Pointers[i]);
448454

449455
// Special Registration for Gaze
450-
if (inputSource.SourceId == InputSystem.GazeProvider.GazeInputSource.SourceId && gazeProviderPointingData == null)
456+
if (inputSource.SourceId == MixedRealityManager.InputSystem.GazeProvider.GazeInputSource.SourceId && gazeProviderPointingData == null)
451457
{
452458
gazeProviderPointingData = new PointerData(inputSource.Pointers[i]);
453459
}
@@ -479,10 +485,10 @@ public bool UnregisterPointer(IMixedRealityPointer pointer)
479485

480486
if (!objectIsStillFocusedByOtherPointer)
481487
{
482-
InputSystem.RaiseFocusExit(pointer, unfocusedObject);
488+
MixedRealityManager.InputSystem.RaiseFocusExit(pointer, unfocusedObject);
483489
}
484490

485-
InputSystem.RaisePreFocusChanged(pointer, unfocusedObject, null);
491+
MixedRealityManager.InputSystem.RaisePreFocusChanged(pointer, unfocusedObject, null);
486492
}
487493

488494
pointers.Remove(pointerData);
@@ -811,21 +817,21 @@ private void UpdateFocusedObjects()
811817
GameObject pendingUnfocusObject = change.PreviousPointerTarget;
812818
GameObject pendingFocusObject = change.CurrentPointerTarget;
813819

814-
InputSystem.RaisePreFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
820+
MixedRealityManager.InputSystem.RaisePreFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
815821

816822
if (pendingOverallFocusExitSet.Contains(pendingUnfocusObject))
817823
{
818-
InputSystem.RaiseFocusExit(change.Pointer, pendingUnfocusObject);
824+
MixedRealityManager.InputSystem.RaiseFocusExit(change.Pointer, pendingUnfocusObject);
819825
pendingOverallFocusExitSet.Remove(pendingUnfocusObject);
820826
}
821827

822828
if (pendingOverallFocusEnterSet.Contains(pendingFocusObject))
823829
{
824-
InputSystem.RaiseFocusEnter(change.Pointer, pendingFocusObject);
830+
MixedRealityManager.InputSystem.RaiseFocusEnter(change.Pointer, pendingFocusObject);
825831
pendingOverallFocusEnterSet.Remove(pendingFocusObject);
826832
}
827833

828-
InputSystem.RaiseFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
834+
MixedRealityManager.InputSystem.RaiseFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
829835
}
830836

831837
Debug.Assert(pendingOverallFocusExitSet.Count == 0);
@@ -855,7 +861,7 @@ public void OnSourceLost(SourceStateEventData eventData)
855861
if (gazeProviderPointingData != null && eventData.InputSource.Pointers[i].PointerId == gazeProviderPointingData.Pointer.PointerId)
856862
{
857863
// If the source lost is the gaze input source, then reset it.
858-
if (eventData.InputSource.SourceId == InputSystem.GazeProvider.GazeInputSource.SourceId)
864+
if (eventData.InputSource.SourceId == MixedRealityManager.InputSystem.GazeProvider.GazeInputSource.SourceId)
859865
{
860866
gazeProviderPointingData.ResetFocusedObjects();
861867
gazeProviderPointingData = null;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Devices;
88
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
99
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem.Handlers;
10+
using Microsoft.MixedReality.Toolkit.Core.Managers;
1011
using Microsoft.MixedReality.Toolkit.Core.Utilities;
1112
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
1213
using Microsoft.MixedReality.Toolkit.Core.Utilities.Physics;
@@ -234,7 +235,7 @@ public override bool TryGetPointerRotation(out Quaternion rotation)
234235
/// <param name="handedness">Optional handedness of the source that pressed the pointer.</param>
235236
public void RaisePointerDown(MixedRealityInputAction mixedRealityInputAction, Handedness handedness = Handedness.None)
236237
{
237-
InputSystem.RaisePointerDown(this, handedness, mixedRealityInputAction);
238+
MixedRealityManager.InputSystem.RaisePointerDown(this, handedness, mixedRealityInputAction);
238239
}
239240

240241
/// <summary>
@@ -244,8 +245,8 @@ public void RaisePointerDown(MixedRealityInputAction mixedRealityInputAction, Ha
244245
/// <param name="handedness">Optional handedness of the source that released the pointer.</param>
245246
public void RaisePointerUp(MixedRealityInputAction mixedRealityInputAction, Handedness handedness = Handedness.None)
246247
{
247-
InputSystem.RaisePointerClicked(this, handedness, mixedRealityInputAction, 0);
248-
InputSystem.RaisePointerUp(this, handedness, mixedRealityInputAction);
248+
MixedRealityManager.InputSystem.RaisePointerClicked(this, handedness, mixedRealityInputAction, 0);
249+
MixedRealityManager.InputSystem.RaisePointerUp(this, handedness, mixedRealityInputAction);
249250
}
250251
}
251252

@@ -341,7 +342,7 @@ protected override void OnDisable()
341342
{
342343
base.OnDisable();
343344
GazePointer.BaseCursor?.SetVisibility(false);
344-
InputSystem?.RaiseSourceLost(GazeInputSource);
345+
MixedRealityManager.InputSystem?.RaiseSourceLost(GazeInputSource);
345346
}
346347

347348
#endregion MonoBehaviour Implementation
@@ -394,7 +395,7 @@ private IMixedRealityPointer InitializeGazePointer()
394395
private async void RaiseSourceDetected()
395396
{
396397
await WaitUntilInputSystemValid;
397-
InputSystem.RaiseSourceDetected(GazeInputSource);
398+
MixedRealityManager.InputSystem.RaiseSourceDetected(GazeInputSource);
398399
GazePointer.BaseCursor?.SetVisibility(true);
399400
}
400401

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
55
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
66
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem.Handlers;
7-
using Microsoft.MixedReality.Toolkit.Core.Managers;
87
using System.Collections.Generic;
98
using UnityEngine;
109

@@ -16,9 +15,6 @@ namespace Microsoft.MixedReality.Toolkit.SDK.Input.Handlers
1615
[RequireComponent(typeof(Collider))]
1716
public abstract class BaseFocusHandler : MonoBehaviour, IMixedRealityFocusHandler
1817
{
19-
private static IMixedRealityInputSystem inputSystem = null;
20-
protected static IMixedRealityInputSystem InputSystem => inputSystem ?? (inputSystem = MixedRealityManager.Instance.GetManager<IMixedRealityInputSystem>());
21-
2218
[SerializeField]
2319
[Tooltip("Is focus enabled for this component?")]
2420
private bool focusEnabled = true;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
77
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
88
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem.Handlers;
9+
using Microsoft.MixedReality.Toolkit.Core.Managers;
910
using Microsoft.MixedReality.Toolkit.Core.Utilities;
1011
using UnityEngine;
1112

@@ -134,7 +135,7 @@ void IMixedRealityPointerHandler.OnPointerDown(MixedRealityPointerEventData even
134135
currentPointer = eventData.Pointer;
135136

136137
FocusDetails focusDetails;
137-
Vector3 initialDraggingPosition = InputSystem.FocusProvider.TryGetFocusDetails(eventData, out focusDetails)
138+
Vector3 initialDraggingPosition = MixedRealityManager.InputSystem.FocusProvider.TryGetFocusDetails(eventData, out focusDetails)
138139
? focusDetails.Point
139140
: hostTransform.position;
140141

@@ -200,7 +201,7 @@ private void StartDragging(Vector3 initialDraggingPosition)
200201
// TODO: robertes: Fix push/pop and single-handler model so that multiple HandDraggable components can be active at once.
201202

202203
// Add self as a modal input handler, to get all inputs during the manipulation
203-
InputSystem.PushModalInputHandler(gameObject);
204+
MixedRealityManager.InputSystem.PushModalInputHandler(gameObject);
204205

205206
isDragging = true;
206207

@@ -326,7 +327,7 @@ private void StopDragging()
326327
}
327328

328329
// Remove self as a modal input handler
329-
InputSystem.PopModalInputHandler();
330+
MixedRealityManager.InputSystem.PopModalInputHandler();
330331

331332
isDragging = false;
332333

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ namespace Microsoft.MixedReality.Toolkit.SDK.Input.Handlers
1515
/// </summary>
1616
public class TeleportHotSpot : BaseFocusHandler, IMixedRealityTeleportHotSpot
1717
{
18-
private static IMixedRealityTeleportSystem teleportSystem = null;
19-
protected static IMixedRealityTeleportSystem TeleportSystem => teleportSystem ?? (teleportSystem = MixedRealityManager.Instance.GetManager<IMixedRealityTeleportSystem>());
20-
2118
#region IMixedRealityFocusHandler Implementation
2219

2320
/// <inheritdoc />
@@ -33,8 +30,8 @@ public override void OnBeforeFocusChange(FocusEventData eventData)
3330

3431
if (eventData.Pointer.IsInteractionEnabled)
3532
{
36-
TeleportSystem.RaiseTeleportCanceled(eventData.Pointer, this);
37-
TeleportSystem.RaiseTeleportRequest(eventData.Pointer, this);
33+
MixedRealityManager.TeleportSystem?.RaiseTeleportCanceled(eventData.Pointer, this);
34+
MixedRealityManager.TeleportSystem?.RaiseTeleportRequest(eventData.Pointer, this);
3835
}
3936
}
4037
else if (eventData.OldFocusedObject == gameObject)
@@ -43,7 +40,7 @@ public override void OnBeforeFocusChange(FocusEventData eventData)
4340

4441
if (eventData.Pointer.IsInteractionEnabled)
4542
{
46-
TeleportSystem.RaiseTeleportCanceled(eventData.Pointer, this);
43+
MixedRealityManager.TeleportSystem?.RaiseTeleportCanceled(eventData.Pointer, this);
4744
}
4845
}
4946
}
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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.Core.Interfaces.InputSystem;
54
using Microsoft.MixedReality.Toolkit.Core.Managers;
65
using Microsoft.MixedReality.Toolkit.Core.Utilities.Async;
76
using UnityEngine;
@@ -13,18 +12,15 @@ namespace Microsoft.MixedReality.Toolkit.SDK.Input
1312
/// </summary>
1413
public class InputSystemGlobalListener : MonoBehaviour
1514
{
16-
private static IMixedRealityInputSystem inputSystem = null;
17-
protected static IMixedRealityInputSystem InputSystem => inputSystem ?? (inputSystem = MixedRealityManager.Instance.GetManager<IMixedRealityInputSystem>());
18-
1915
private bool lateInitialize = true;
2016

21-
protected readonly WaitUntil WaitUntilInputSystemValid = new WaitUntil(() => InputSystem != null);
17+
protected readonly WaitUntil WaitUntilInputSystemValid = new WaitUntil(() => MixedRealityManager.InputSystem != null);
2218

2319
protected virtual void OnEnable()
2420
{
25-
if (MixedRealityManager.IsInitialized && InputSystem != null && !lateInitialize)
21+
if (MixedRealityManager.IsInitialized && MixedRealityManager.InputSystem != null && !lateInitialize)
2622
{
27-
InputSystem.Register(gameObject);
23+
MixedRealityManager.InputSystem.Register(gameObject);
2824
}
2925
}
3026

@@ -34,13 +30,13 @@ protected virtual async void Start()
3430
{
3531
await WaitUntilInputSystemValid;
3632
lateInitialize = false;
37-
InputSystem.Register(gameObject);
33+
MixedRealityManager.InputSystem.Register(gameObject);
3834
}
3935
}
4036

4137
protected virtual void OnDisable()
4238
{
43-
InputSystem?.Unregister(gameObject);
39+
MixedRealityManager.InputSystem?.Unregister(gameObject);
4440
}
4541
}
4642
}

0 commit comments

Comments
 (0)