Skip to content

Commit 9b1b3bd

Browse files
author
David Kline (ANALOG)
committed
update input system
1 parent a299d00 commit 9b1b3bd

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

Assets/MixedRealityToolkit.Services/InputSystem/MixedRealityInputSystem.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
using UnityEngine;
1717
using UnityEngine.EventSystems;
1818
using Microsoft.MixedReality.Toolkit.Core.Services;
19+
using Microsoft.MixedReality.Toolkit.Core.Interfaces;
1920

2021
namespace Microsoft.MixedReality.Toolkit.Services.InputSystem
2122
{
2223
/// <summary>
2324
/// The Mixed Reality Toolkit's specific implementation of the <see cref="Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem.IMixedRealityInputSystem"/>
2425
/// </summary>
25-
public class MixedRealityInputSystem : BaseEventSystem, IMixedRealityInputSystem
26+
public class MixedRealityInputSystem : BaseCoreSystem, IMixedRealityInputSystem
2627
{
28+
public MixedRealityInputSystem(
29+
IMixedRealityServiceRegistrar registrar,
30+
MixedRealityInputSystemProfile profile) : base(registrar, profile) { }
31+
2732
/// <inheritdoc />
2833
public event Action InputEnabled;
2934

@@ -39,7 +44,7 @@ public class MixedRealityInputSystem : BaseEventSystem, IMixedRealityInputSystem
3944
private IMixedRealityFocusProvider focusProvider = null;
4045

4146
/// <inheritdoc />
42-
public IMixedRealityFocusProvider FocusProvider => focusProvider ?? (focusProvider = MixedRealityToolkit.Instance.GetService<IMixedRealityFocusProvider>());
47+
public IMixedRealityFocusProvider FocusProvider => focusProvider ?? (focusProvider = Registrar.GetService<IMixedRealityFocusProvider>());
4348

4449
/// <inheritdoc />
4550
public IMixedRealityGazeProvider GazeProvider { get; private set; }
@@ -88,6 +93,9 @@ public override void Initialize()
8893
{
8994
bool addedComponents = false;
9095

96+
MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile;
97+
if (profile == null) { return; }
98+
9199
if (!Application.isPlaying)
92100
{
93101
var standaloneInputModules = UnityEngine.Object.FindObjectsOfType<StandaloneInputModule>();
@@ -125,27 +133,27 @@ public override void Initialize()
125133
CameraCache.Main.gameObject.EnsureComponent<StandaloneInputModule>();
126134
}
127135

128-
if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile == null)
136+
if (profile == null)
129137
{
130138
Debug.LogError("The Input system is missing the required Input System Profile!");
131139
return;
132140
}
133141

134-
if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionRulesProfile != null)
142+
if (profile.InputActionRulesProfile != null)
135143
{
136-
CurrentInputActionRulesProfile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionRulesProfile;
144+
CurrentInputActionRulesProfile = profile.InputActionRulesProfile;
137145
}
138146
else
139147
{
140148
Debug.LogError("The Input system is missing the required Input Action Rules Profile!");
141149
return;
142150
}
143151

144-
if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile != null)
152+
if (profile.PointerProfile != null)
145153
{
146-
if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile.GazeProviderType?.Type != null)
154+
if (profile.PointerProfile.GazeProviderType?.Type != null)
147155
{
148-
GazeProvider = CameraCache.Main.gameObject.EnsureComponent(MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.PointerProfile.GazeProviderType.Type) as IMixedRealityGazeProvider;
156+
GazeProvider = CameraCache.Main.gameObject.EnsureComponent(profile.PointerProfile.GazeProviderType.Type) as IMixedRealityGazeProvider;
149157
}
150158
else
151159
{

Assets/MixedRealityToolkit.Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs

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

44
using Microsoft.MixedReality.Toolkit.Core.Definitions.SpatialAwarenessSystem;
55
using Microsoft.MixedReality.Toolkit.Core.EventDatum.SpatialAwarenessSystem;
6+
using Microsoft.MixedReality.Toolkit.Core.Interfaces;
67
using Microsoft.MixedReality.Toolkit.Core.Interfaces.SpatialAwarenessSystem;
78
using Microsoft.MixedReality.Toolkit.Core.Interfaces.SpatialAwarenessSystem.Handlers;
89
using Microsoft.MixedReality.Toolkit.Core.Interfaces.SpatialAwarenessSystem.Observers;
@@ -16,8 +17,11 @@ namespace Microsoft.MixedReality.Toolkit.Services.SpatialAwarenessSystem
1617
/// <summary>
1718
/// Class providing the default implementation of the <see cref="Microsoft.MixedReality.Toolkit.Core.Interfaces.SpatialAwarenessSystem.IMixedRealitySpatialAwarenessSystem"/> interface.
1819
/// </summary>
19-
public class MixedRealitySpatialAwarenessSystem : BaseEventSystem, IMixedRealitySpatialAwarenessSystem
20+
public class MixedRealitySpatialAwarenessSystem : BaseCoreSystem, IMixedRealitySpatialAwarenessSystem
2021
{
22+
public MixedRealitySpatialAwarenessSystem(IMixedRealityServiceRegistrar registrar) : base(registrar, null) // spatial awareness does not yet use a profile
23+
{ }
24+
2125
#region IMixedRealityToolkit Implementation
2226

2327
private MixedRealitySpatialAwarenessEventData<SpatialAwarenessMeshObject> meshEventData = null;
@@ -59,7 +63,7 @@ public override void Enable()
5963
}
6064

6165
// Get the collection of registered observers.
62-
IReadOnlyList<IMixedRealitySpatialAwarenessObserver> services = MixedRealityToolkit.Instance.GetServices<IMixedRealitySpatialAwarenessObserver>();
66+
IReadOnlyList<IMixedRealitySpatialAwarenessObserver> services = Registrar.GetServices<IMixedRealitySpatialAwarenessObserver>();
6367
for (int i = 0; i < services.Count; i++)
6468
{
6569
observers.Add(services[i] as IMixedRealitySpatialAwarenessObserver);

Assets/MixedRealityToolkit.Tests/InputSystem/TestFixture_03_InputSystemTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void Test01_CreateMixedRealityInputSystem()
3434
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile = inputSystemProfile;
3535

3636
// Add Input System
37-
MixedRealityToolkit.Instance.RegisterService<IMixedRealityInputSystem>(new MixedRealityInputSystem());
37+
MixedRealityToolkit.Instance.RegisterService<IMixedRealityInputSystem>(new MixedRealityInputSystem(MixedRealityToolkit.Instance, MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile));
3838

3939
// Tests
4040
Assert.IsNotEmpty(MixedRealityToolkit.Instance.ActiveSystems);

Assets/MixedRealityToolkit/Services/MixedRealityToolkit.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ private void InitializeServiceLocator()
363363
Utilities.Editor.InputMappingAxisUtility.CheckUnityInputManagerMappings(Definitions.Devices.ControllerMappingLibrary.UnityInputManagerAxes);
364364
#endif
365365

366-
if (!RegisterService<IMixedRealityInputSystem>(ActiveProfile.InputSystemType) || InputSystem == null)
366+
object[] args = { this, ActiveProfile.InputSystemProfile };
367+
368+
if (!RegisterService<IMixedRealityInputSystem>(ActiveProfile.InputSystemType, args: args) || InputSystem == null)
367369
{
368370
Debug.LogError("Failed to start the Input System!");
369371
}
@@ -398,7 +400,9 @@ private void InitializeServiceLocator()
398400
#if UNITY_EDITOR
399401
LayerExtensions.SetupLayer(31, "Spatial Awareness");
400402
#endif
401-
if (!RegisterService<IMixedRealitySpatialAwarenessSystem>(ActiveProfile.SpatialAwarenessSystemSystemType) && SpatialAwarenessSystem != null)
403+
object[] args = { this }; // todo: add profile
404+
405+
if (!RegisterService<IMixedRealitySpatialAwarenessSystem>(ActiveProfile.SpatialAwarenessSystemSystemType, args: args) && SpatialAwarenessSystem != null)
402406
{
403407
Debug.LogError("Failed to start the Spatial Awareness System!");
404408
}

0 commit comments

Comments
 (0)