Skip to content

Commit 4d9f5cb

Browse files
centralized all the core manager accessors to MixedRealiyManager
1 parent 720d9c5 commit 4d9f5cb

34 files changed

+229
-263
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ namespace Microsoft.MixedReality.Toolkit.Examples.Demos
1717
/// </summary>
1818
public class BoundaryVisualizationDemo : MonoBehaviour, IMixedRealityBoundaryHandler
1919
{
20-
private IMixedRealityBoundarySystem BoundaryManager => boundaryManager ?? (boundaryManager = MixedRealityManager.Instance.GetManager<IMixedRealityBoundarySystem>());
21-
private IMixedRealityBoundarySystem boundaryManager = null;
22-
2320
private GameObject markerParent;
2421
private readonly List<GameObject> markers = new List<GameObject>();
2522

@@ -50,7 +47,7 @@ private void Awake()
5047
private void Start()
5148
{
5249

53-
if (BoundaryManager != null)
50+
if (MixedRealityManager.BoundarySystem != null)
5451
{
5552
if (markers.Count == 0)
5653
{
@@ -61,24 +58,24 @@ private void Start()
6158

6259
private void Update()
6360
{
64-
if (BoundaryManager != null)
61+
if (MixedRealityManager.BoundarySystem != null)
6562
{
66-
BoundaryManager.ShowFloor = showFloor;
67-
BoundaryManager.ShowPlayArea = showPlayArea;
68-
BoundaryManager.ShowTrackedArea = showTrackedArea;
69-
BoundaryManager.ShowBoundaryWalls = showBoundaryWalls;
70-
BoundaryManager.ShowBoundaryCeiling = showBoundaryCeiling;
63+
MixedRealityManager.BoundarySystem.ShowFloor = showFloor;
64+
MixedRealityManager.BoundarySystem.ShowPlayArea = showPlayArea;
65+
MixedRealityManager.BoundarySystem.ShowTrackedArea = showTrackedArea;
66+
MixedRealityManager.BoundarySystem.ShowBoundaryWalls = showBoundaryWalls;
67+
MixedRealityManager.BoundarySystem.ShowBoundaryCeiling = showBoundaryCeiling;
7168
}
7269
}
7370

7471
private void OnEnable()
7572
{
76-
BoundaryManager.Register(gameObject);
73+
MixedRealityManager.BoundarySystem.Register(gameObject);
7774
}
7875

7976
private void OnDisable()
8077
{
81-
BoundaryManager.Unregister(gameObject);
78+
MixedRealityManager.BoundarySystem.Unregister(gameObject);
8279
}
8380

8481
#endregion MonoBehaviour Implementation
@@ -105,7 +102,7 @@ private void AddMarkers()
105102
float widthRect;
106103
float heightRect;
107104

108-
if (!BoundaryManager.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
105+
if (!MixedRealityManager.BoundarySystem.TryGetRectangularBoundsParams(out centerRect, out angleRect, out widthRect, out heightRect))
109106
{
110107
// If we have no boundary manager or rectangular bounds we will show no indicators
111108
return;
@@ -136,12 +133,12 @@ private void AddMarkers()
136133

137134
Material material = null;
138135
// Check inscribed rectangle first
139-
if (BoundaryManager.Contains(position, Boundary.Type.PlayArea))
136+
if (MixedRealityManager.BoundarySystem.Contains(position, Boundary.Type.PlayArea))
140137
{
141138
material = visualizationProfile.PlayAreaMaterial;
142139
}
143140
// Then check geometry
144-
else if (BoundaryManager.Contains(position, Boundary.Type.TrackedArea))
141+
else if (MixedRealityManager.BoundarySystem.Contains(position, Boundary.Type.TrackedArea))
145142
{
146143
material = visualizationProfile.TrackedAreaMaterial;
147144
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
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;
910
using Microsoft.MixedReality.Toolkit.Core.Utilities.Physics;
1011
using System;
@@ -232,7 +233,7 @@ private void Awake()
232233
CreateUiRaycastCamera();
233234
}
234235

235-
foreach (var inputSource in InputSystem.DetectedInputSources)
236+
foreach (var inputSource in MixedRealityManager.InputSystem.DetectedInputSources)
236237
{
237238
RegisterPointers(inputSource);
238239
}
@@ -447,7 +448,7 @@ private void RegisterPointers(IMixedRealityInputSource inputSource)
447448
RegisterPointer(inputSource.Pointers[i]);
448449

449450
// Special Registration for Gaze
450-
if (inputSource.SourceId == InputSystem.GazeProvider.GazeInputSource.SourceId && gazeProviderPointingData == null)
451+
if (inputSource.SourceId == MixedRealityManager.InputSystem.GazeProvider.GazeInputSource.SourceId && gazeProviderPointingData == null)
451452
{
452453
gazeProviderPointingData = new PointerData(inputSource.Pointers[i]);
453454
}
@@ -479,10 +480,10 @@ public bool UnregisterPointer(IMixedRealityPointer pointer)
479480

480481
if (!objectIsStillFocusedByOtherPointer)
481482
{
482-
InputSystem.RaiseFocusExit(pointer, unfocusedObject);
483+
MixedRealityManager.InputSystem.RaiseFocusExit(pointer, unfocusedObject);
483484
}
484485

485-
InputSystem.RaisePreFocusChanged(pointer, unfocusedObject, null);
486+
MixedRealityManager.InputSystem.RaisePreFocusChanged(pointer, unfocusedObject, null);
486487
}
487488

488489
pointers.Remove(pointerData);
@@ -812,21 +813,21 @@ private void UpdateFocusedObjects()
812813
GameObject pendingUnfocusObject = change.PreviousPointerTarget;
813814
GameObject pendingFocusObject = change.CurrentPointerTarget;
814815

815-
InputSystem.RaisePreFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
816+
MixedRealityManager.InputSystem.RaisePreFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
816817

817818
if (pendingOverallFocusExitSet.Contains(pendingUnfocusObject))
818819
{
819-
InputSystem.RaiseFocusExit(change.Pointer, pendingUnfocusObject);
820+
MixedRealityManager.InputSystem.RaiseFocusExit(change.Pointer, pendingUnfocusObject);
820821
pendingOverallFocusExitSet.Remove(pendingUnfocusObject);
821822
}
822823

823824
if (pendingOverallFocusEnterSet.Contains(pendingFocusObject))
824825
{
825-
InputSystem.RaiseFocusEnter(change.Pointer, pendingFocusObject);
826+
MixedRealityManager.InputSystem.RaiseFocusEnter(change.Pointer, pendingFocusObject);
826827
pendingOverallFocusEnterSet.Remove(pendingFocusObject);
827828
}
828829

829-
InputSystem.RaiseFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
830+
MixedRealityManager.InputSystem.RaiseFocusChanged(change.Pointer, pendingUnfocusObject, pendingFocusObject);
830831
}
831832

832833
Debug.Assert(pendingOverallFocusExitSet.Count == 0);
@@ -856,7 +857,7 @@ public void OnSourceLost(SourceStateEventData eventData)
856857
if (gazeProviderPointingData != null && eventData.InputSource.Pointers[i].PointerId == gazeProviderPointingData.Pointer.PointerId)
857858
{
858859
// If the source lost is the gaze input source, then reset it.
859-
if (eventData.InputSource.SourceId == InputSystem.GazeProvider.GazeInputSource.SourceId)
860+
if (eventData.InputSource.SourceId == MixedRealityManager.InputSystem.GazeProvider.GazeInputSource.SourceId)
860861
{
861862
gazeProviderPointingData.ResetFocusedObjects();
862863
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

@@ -339,7 +340,7 @@ protected override void OnDisable()
339340
{
340341
base.OnDisable();
341342
GazePointer.BaseCursor?.SetVisibility(false);
342-
InputSystem?.RaiseSourceLost(GazeInputSource);
343+
MixedRealityManager.InputSystem?.RaiseSourceLost(GazeInputSource);
343344
}
344345

345346
#endregion MonoBehaviour Implementation
@@ -392,7 +393,7 @@ private IMixedRealityPointer InitializeGazePointer()
392393
private async void RaiseSourceDetected()
393394
{
394395
await WaitUntilInputSystemValid;
395-
InputSystem.RaiseSourceDetected(GazeInputSource);
396+
MixedRealityManager.InputSystem.RaiseSourceDetected(GazeInputSource);
396397
GazePointer.BaseCursor?.SetVisibility(true);
397398
}
398399

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 capabilities 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
}

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.MixedReality.Toolkit.Core.Definitions.Physics;
66
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
77
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
8+
using Microsoft.MixedReality.Toolkit.Core.Managers;
89
using Microsoft.MixedReality.Toolkit.SDK.Input;
910
using Microsoft.MixedReality.Toolkit.SDK.UX.Pointers;
1011
using UnityEngine;
@@ -262,10 +263,10 @@ private void OnDestroy()
262263
protected virtual void RegisterManagers()
263264
{
264265
// Register the cursor as a listener, so that it can always get input events it cares about
265-
InputSystem.Register(gameObject);
266+
MixedRealityManager.InputSystem.Register(gameObject);
266267

267268
// Setup the cursor to be able to respond to input being globally enabled / disabled
268-
if (InputSystem.IsInputEnabled)
269+
if (MixedRealityManager.InputSystem.IsInputEnabled)
269270
{
270271
OnInputEnabled();
271272
}
@@ -274,18 +275,18 @@ protected virtual void RegisterManagers()
274275
OnInputDisabled();
275276
}
276277

277-
InputSystem.InputEnabled += OnInputEnabled;
278-
InputSystem.InputDisabled += OnInputDisabled;
278+
MixedRealityManager.InputSystem.InputEnabled += OnInputEnabled;
279+
MixedRealityManager.InputSystem.InputDisabled += OnInputDisabled;
279280
}
280281

281282
/// <summary>
282283
/// Unregister from events from the managers the cursor needs.
283284
/// </summary>
284285
protected virtual void UnregisterManagers()
285286
{
286-
InputSystem.InputEnabled -= OnInputEnabled;
287-
InputSystem.InputDisabled -= OnInputDisabled;
288-
InputSystem.Unregister(gameObject);
287+
MixedRealityManager.InputSystem.InputEnabled -= OnInputEnabled;
288+
MixedRealityManager.InputSystem.InputDisabled -= OnInputDisabled;
289+
MixedRealityManager.InputSystem.Unregister(gameObject);
289290
}
290291

291292
/// <summary>
@@ -301,17 +302,17 @@ protected virtual void UpdateCursorTransform()
301302

302303
FocusDetails focusDetails;
303304

304-
if (!Pointer.InputSystem.FocusProvider.TryGetFocusDetails(Pointer, out focusDetails))
305+
if (!MixedRealityManager.InputSystem.FocusProvider.TryGetFocusDetails(Pointer, out focusDetails))
305306
{
306-
if (Pointer.InputSystem.FocusProvider.IsPointerRegistered(Pointer))
307+
if (MixedRealityManager.InputSystem.FocusProvider.IsPointerRegistered(Pointer))
307308
{
308309
Debug.LogError($"{name}: Unable to get focus details for {pointer.GetType().Name}!");
309310
}
310311

311312
return;
312313
}
313314

314-
GameObject newTargetedObject = Pointer.InputSystem.FocusProvider.GetFocusedObject(Pointer);
315+
GameObject newTargetedObject = MixedRealityManager.InputSystem.FocusProvider.GetFocusedObject(Pointer);
315316
Vector3 lookForward;
316317

317318
// Normalize scale on before update

0 commit comments

Comments
 (0)