Skip to content

Commit 632fc33

Browse files
author
David Kline (ANALOG)
committed
update focus provider
1 parent 9b1b3bd commit 632fc33

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

Assets/MixedRealityToolkit.Services/InputSystem/FocusProvider.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
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.Definitions.InputSystem;
45
using Microsoft.MixedReality.Toolkit.Core.Definitions.Physics;
56
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
67
using Microsoft.MixedReality.Toolkit.Core.Extensions;
8+
using Microsoft.MixedReality.Toolkit.Core.Interfaces;
79
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
810
using Microsoft.MixedReality.Toolkit.Core.Services;
911
using Microsoft.MixedReality.Toolkit.Core.Utilities;
@@ -19,8 +21,14 @@ namespace Microsoft.MixedReality.Toolkit.Services.InputSystem
1921
/// The focus provider handles the focused objects per input source.
2022
/// <remarks>There are convenience properties for getting only Gaze Pointer if needed.</remarks>
2123
/// </summary>
22-
public class FocusProvider : BaseService, IMixedRealityFocusProvider
24+
public class FocusProvider : BaseDataProvider, IMixedRealityFocusProvider
2325
{
26+
public FocusProvider(
27+
IMixedRealityServiceRegistrar registrar,
28+
IMixedRealityInputSystem inputSystem,
29+
MixedRealityInputSystemProfile profile) : base(registrar, inputSystem, null, DefaultPriority, profile)
30+
{ }
31+
2432
private readonly HashSet<PointerData> pointers = new HashSet<PointerData>();
2533
private readonly HashSet<GameObject> pendingOverallFocusEnterSet = new HashSet<GameObject>();
2634
private readonly HashSet<GameObject> pendingOverallFocusExitSet = new HashSet<GameObject>();
@@ -39,11 +47,13 @@ float IMixedRealityFocusProvider.GlobalPointingExtent
3947
{
4048
get
4149
{
42-
if (MixedRealityToolkit.Instance.HasActiveProfile &&
43-
MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
44-
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile != null)
50+
MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile;
51+
52+
if ((Service != null) &&
53+
(profile != null) &&
54+
profile.PointerProfile != null)
4555
{
46-
return MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile.PointingExtent;
56+
return profile.PointerProfile.PointingExtent;
4757
}
4858

4959
return 10f;
@@ -59,11 +69,13 @@ public LayerMask[] FocusLayerMasks
5969
{
6070
if (focusLayerMasks == null)
6171
{
62-
if (MixedRealityToolkit.Instance.HasActiveProfile &&
63-
MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
64-
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile != null)
72+
MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile;
73+
74+
if ((Service != null) &&
75+
(profile != null) &&
76+
profile.PointerProfile != null)
6577
{
66-
return focusLayerMasks = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile.PointingRaycastLayerMasks;
78+
return focusLayerMasks = profile.PointerProfile.PointingRaycastLayerMasks;
6779
}
6880

6981
return focusLayerMasks = new LayerMask[] { Physics.DefaultRaycastLayers };
@@ -102,21 +114,21 @@ private bool IsSetupValid
102114
{
103115
get
104116
{
105-
if (!MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled) { return false; }
106-
107-
if (MixedRealityToolkit.InputSystem == null)
117+
if (Service == null)
108118
{
109119
Debug.LogError($"Unable to start {Name}. An Input System is required for this feature.");
110120
return false;
111121
}
112122

113-
if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile == null)
123+
MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile;
124+
125+
if (profile == null)
114126
{
115127
Debug.LogError($"Unable to start {Name}. An Input System Profile is required for this feature.");
116128
return false;
117129
}
118130

119-
if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile == null)
131+
if (profile.PointerProfile == null)
120132
{
121133
Debug.LogError($"Unable to start {Name}. An Pointer Profile is required for this feature.");
122134
return false;
@@ -563,15 +575,18 @@ private void UpdatePointers()
563575
{
564576
int pointerCount = 0;
565577

578+
MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile;
579+
if (profile == null) { return; }
580+
566581
foreach (var pointer in pointers)
567582
{
568583
UpdatePointer(pointer);
569584

570-
var pointerProfile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile;
585+
var pointerProfile = profile.PointerProfile;
571586

572587
if (pointerProfile != null && pointerProfile.DebugDrawPointingRays)
573588
{
574-
MixedRealityRaycaster.DebugEnabled = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile.DebugDrawPointingRays;
589+
MixedRealityRaycaster.DebugEnabled = pointerProfile.DebugDrawPointingRays;
575590

576591
Color rayColor;
577592

Assets/MixedRealityToolkit/Services/MixedRealityToolkit.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,13 @@ private void InitializeServiceLocator()
364364
#endif
365365

366366
object[] args = { this, ActiveProfile.InputSystemProfile };
367-
368367
if (!RegisterService<IMixedRealityInputSystem>(ActiveProfile.InputSystemType, args: args) || InputSystem == null)
369368
{
370369
Debug.LogError("Failed to start the Input System!");
371370
}
372-
373-
if (!RegisterService<IMixedRealityFocusProvider>(ActiveProfile.InputSystemProfile.FocusProviderType))
371+
372+
args = new object[] { this, InputSystem, ActiveProfile.InputSystemProfile };
373+
if (!RegisterDataProvider<IMixedRealityFocusProvider>(ActiveProfile.InputSystemProfile.FocusProviderType, args: args))
374374
{
375375
Debug.LogError("Failed to register the focus provider! The input system will not function without it.");
376376
return;
@@ -387,7 +387,6 @@ private void InitializeServiceLocator()
387387
if (ActiveProfile.IsBoundarySystemEnabled)
388388
{
389389
object[] args = { this, ActiveProfile.BoundaryVisualizationProfile, Instance.MixedRealityPlayspace, ActiveProfile.TargetExperienceScale };
390-
391390
if (!RegisterService<IMixedRealityBoundarySystem>(ActiveProfile.BoundarySystemSystemType, args: args) || BoundarySystem == null)
392391
{
393392
Debug.LogError("Failed to start the Boundary System!");
@@ -401,7 +400,6 @@ private void InitializeServiceLocator()
401400
LayerExtensions.SetupLayer(31, "Spatial Awareness");
402401
#endif
403402
object[] args = { this }; // todo: add profile
404-
405403
if (!RegisterService<IMixedRealitySpatialAwarenessSystem>(ActiveProfile.SpatialAwarenessSystemSystemType, args: args) && SpatialAwarenessSystem != null)
406404
{
407405
Debug.LogError("Failed to start the Spatial Awareness System!");
@@ -412,7 +410,6 @@ private void InitializeServiceLocator()
412410
if (ActiveProfile.IsTeleportSystemEnabled)
413411
{
414412
object[] args = { this, Instance.MixedRealityPlayspace };
415-
416413
if (!RegisterService<IMixedRealityTeleportSystem>(ActiveProfile.TeleportSystemSystemType, args: args) || TeleportSystem == null)
417414
{
418415
Debug.LogError("Failed to start the Teleport System!");
@@ -422,7 +419,6 @@ private void InitializeServiceLocator()
422419
if (ActiveProfile.IsDiagnosticsSystemEnabled)
423420
{
424421
object[] args = { this, ActiveProfile.DiagnosticsSystemProfile, Instance.MixedRealityPlayspace };
425-
426422
if (!RegisterService<IMixedRealityDiagnosticsSystem>(ActiveProfile.DiagnosticsSystemSystemType, args: args) || DiagnosticsSystem == null)
427423
{
428424
Debug.LogError("Failed to start the Diagnostics System!");

0 commit comments

Comments
 (0)