Skip to content

Commit

Permalink
Merge pull request #4593 from davidkline-ms/inputProviderAccess_rc2
Browse files Browse the repository at this point in the history
Add IMixedRealityDataProviderAccess and update how data providers are retrieved

Merging with @wiwei's approval and the previous approval from @Railboy
  • Loading branch information
David Kline authored May 28, 2019
2 parents 64e5dc9 + c4c8af2 commit 83bf0cc
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,21 @@ public abstract class PanZoomBase : MonoBehaviour,
protected Vector2 originalScale;
protected Vector2 originalOffset;

protected IMixedRealityEyeSaccadeProvider EyeSaccadeProvider => eyeSaccadeProvider ?? (eyeSaccadeProvider = MixedRealityToolkit.Instance.GetService<IMixedRealityEyeSaccadeProvider>());
private IMixedRealityEyeSaccadeProvider eyeSaccadeProvider = null;

protected IMixedRealityEyeSaccadeProvider EyeSaccadeProvider
{
get
{
if (eyeSaccadeProvider == null)
{
IMixedRealityEyeGazeDataProvider eyeGazeProvider = (InputSystem as IMixedRealityDataProviderAccess)?.GetDataProvider<IMixedRealityEyeGazeDataProvider>();
eyeSaccadeProvider = eyeGazeProvider?.SaccadeProvider;
}
return eyeSaccadeProvider;
}
}

#endregion

private IMixedRealityInputSystem inputSystem = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public WindowsMixedRealityEyeGazeDataProvider(

public bool SmoothEyeTracking { get; set; } = false;

public IMixedRealityEyeSaccadeProvider SaccadeProvider => this;

private readonly float smoothFactorNormalized = 0.96f;
private readonly float saccadeThreshInDegree = 2.5f; // In degrees (not radians)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected override void Start()
{
base.Start();

dictationSystem = MixedRealityToolkit.Instance.GetService<IMixedRealityDictationSystem>();
dictationSystem = (InputSystem as IMixedRealityDataProviderAccess)?.GetDataProvider<IMixedRealityDictationSystem>();
Debug.Assert(dictationSystem != null, "No dictation system found. In order to use dictation, add a dictation system like 'Windows Dictation Input Provider' to the Data Providers in the Input System profile");

if (startRecordingOnStart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,22 @@ public class MousePointer : BaseControllerPointer, IMixedRealityMousePointer
public override bool IsInteractionEnabled => isInteractionEnabled;

private IMixedRealityController controller;

private MixedRealityMouseInputProfile mouseInputProfile = null;
private MixedRealityMouseInputProfile MouseInputProfile => mouseInputProfile ?? (mouseInputProfile = MixedRealityToolkit.Instance.GetService<MouseDeviceManager>()?.MouseInputProfile);

private MixedRealityMouseInputProfile MouseInputProfile
{
get
{
if (mouseInputProfile == null)
{
// Get the profile from the input system's registered mouse device manager.
IMixedRealityMouseDeviceManager mouseManager = (InputSystem as IMixedRealityDataProviderAccess)?.GetDataProvider<IMixedRealityMouseDeviceManager>();
mouseInputProfile = mouseManager?.MouseInputProfile;
}
return mouseInputProfile;
}
}


/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Handedness Handedness
/// <summary>
/// The active instance of the input system.
/// </summary>
private IMixedRealityInputSystem InputSystem
protected IMixedRealityInputSystem InputSystem
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public bool UpdateSolvers

private GameObject transformWithOffset;

private IMixedRealityHandJointService HandJointService => handJointService ?? (handJointService = MixedRealityToolkit.Instance.GetService<IMixedRealityHandJointService>());
private IMixedRealityHandJointService HandJointService => handJointService ?? (handJointService = (InputSystem as IMixedRealityDataProviderAccess)?.GetDataProvider<IMixedRealityHandJointService>());
private IMixedRealityHandJointService handJointService = null;

#region MonoBehaviour Implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.MixedReality.Toolkit.Input
"Profiles/DefaultMixedRealityInputSimulationProfile.asset",
"MixedRealityToolkit.SDK")]
[DocLink("https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/InputSimulation/InputSimulationService.html")]
public class InputSimulationService : BaseInputDeviceManager, IInputSimulationService
public class InputSimulationService : BaseInputDeviceManager, IInputSimulationService, IMixedRealityEyeGazeDataProvider
{
private ManualCameraControl cameraControl = null;
private SimulatedHandDataProvider handDataProvider = null;
Expand Down Expand Up @@ -49,8 +49,8 @@ public class InputSimulationService : BaseInputDeviceManager, IInputSimulationSe
public InputSimulationService(
IMixedRealityServiceRegistrar registrar,
IMixedRealityInputSystem inputSystem,
string name,
uint priority,
string name,
uint priority,
BaseMixedRealityProfile profile) : base(registrar, inputSystem, name, priority, profile) { }

/// <inheritdoc />
Expand Down Expand Up @@ -97,7 +97,7 @@ public override void Update()

if (profile.SimulateEyePosition)
{
InputSystem?.EyeGazeProvider?.UpdateEyeGaze(null, new Ray(CameraCache.Main.transform.position, CameraCache.Main.transform.forward), System.DateTime.UtcNow);
InputSystem?.EyeGazeProvider?.UpdateEyeGaze(this, new Ray(CameraCache.Main.transform.position, CameraCache.Main.transform.forward), DateTime.UtcNow);
}

switch (profile.HandSimulationMode)
Expand Down Expand Up @@ -163,6 +163,12 @@ public MixedRealityInputSimulationProfile InputSimulationProfile
}
}

/// <inheritdoc/>
IMixedRealityEyeSaccadeProvider IMixedRealityEyeGazeDataProvider.SaccadeProvider => null;

/// <inheritdoc/>
bool IMixedRealityEyeGazeDataProvider.SmoothEyeTracking { get; set; }

private void EnableCameraControl()
{
if (cameraControl == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Microsoft.MixedReality.Toolkit.Input
/// The Mixed Reality Toolkit's specific implementation of the <see cref="Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputSystem"/>
/// </summary>
[DocLink("https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/Input/Overview.html")]
public class MixedRealityInputSystem : BaseCoreSystem, IMixedRealityInputSystem
public class MixedRealityInputSystem : BaseCoreSystem, IMixedRealityInputSystem, IMixedRealityDataProviderAccess
{
public MixedRealityInputSystem(
IMixedRealityServiceRegistrar registrar,
Expand Down Expand Up @@ -272,6 +272,66 @@ public override void Disable()

#endregion IMixedRealityService Implementation

#region GetDataProvider(s) Implementation
/// <inheritdoc />
public IReadOnlyList<IMixedRealityDataProvider> GetDataProviders()
{
return new List<IMixedRealityInputDeviceManager>(deviceManagers) as IReadOnlyList<IMixedRealityInputDeviceManager>;
}

/// <inheritdoc />
public IReadOnlyList<T> GetDataProviders<T>() where T : IMixedRealityDataProvider
{
if (!typeof(IMixedRealityInputDeviceManager).IsAssignableFrom(typeof(T))) { return null; }

List<T> selected = new List<T>();

for (int i = 0; i < deviceManagers.Count; i++)
{
if (deviceManagers[i] is T)
{
selected.Add((T)deviceManagers[i]);
}
}

return selected;
}

/// <inheritdoc />
public IMixedRealityDataProvider GetDataProvider(string name)
{
for (int i = 0; i < deviceManagers.Count; i++)
{
if (deviceManagers[i].Name == name)
{
return deviceManagers[i];
}
}

return null;
}

/// <inheritdoc />
public T GetDataProvider<T>(string name = null) where T : IMixedRealityDataProvider
{
if (!typeof(IMixedRealityInputDeviceManager).IsAssignableFrom(typeof(T))) { return default(T); }

for (int i = 0; i < deviceManagers.Count; i++)
{
if (deviceManagers[i] is T)
{
if ((name == null) || (deviceManagers[i].Name == name))
{
return (T)deviceManagers[i];
}
}
}

return default(T);
}

#endregion GetDataProvider(s) Implementation

#region IMixedRealityEventSystem Implementation

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,25 @@ public MixedRealitySpatialAwarenessSystemProfile SpatialAwarenessSystemProfile

/// <inheritdoc />
public IReadOnlyList<IMixedRealitySpatialAwarenessObserver> GetObservers()
{
return GetDataProviders() as IReadOnlyList<IMixedRealitySpatialAwarenessObserver>;
}

/// <inheritdoc />
public IReadOnlyList<IMixedRealityDataProvider> GetDataProviders()
{
return new List<IMixedRealitySpatialAwarenessObserver>(observers) as IReadOnlyList<IMixedRealitySpatialAwarenessObserver>;
}

/// <inheritdoc />
public IReadOnlyList<T> GetObservers<T>() where T : IMixedRealitySpatialAwarenessObserver
{
return GetDataProviders<T>();
}


/// <inheritdoc />
public IReadOnlyList<T> GetDataProviders<T>() where T : IMixedRealityDataProvider
{
List<T> selected = new List<T>();

Expand All @@ -214,6 +227,12 @@ public IReadOnlyList<T> GetObservers<T>() where T : IMixedRealitySpatialAwarenes

/// <inheritdoc />
public IMixedRealitySpatialAwarenessObserver GetObserver(string name)
{
return GetDataProvider(name) as IMixedRealitySpatialAwarenessObserver;
}

/// <inheritdoc />
public IMixedRealityDataProvider GetDataProvider(string name)
{
for (int i = 0; i < observers.Count; i++)
{
Expand All @@ -227,13 +246,22 @@ public IMixedRealitySpatialAwarenessObserver GetObserver(string name)
}

/// <inheritdoc />
public T GetObserver<T>(string name) where T : IMixedRealitySpatialAwarenessObserver
public T GetObserver<T>(string name = null) where T : IMixedRealitySpatialAwarenessObserver
{
return GetDataProvider<T>(name);
}

/// <inheritdoc />
public T GetDataProvider<T>(string name = null) where T : IMixedRealityDataProvider
{
for (int i = 0; i < observers.Count; i++)
{
if ((observers[i] is T) && (observers[i].Name == name))
if (observers[i] is T)
{
return (T)observers[i];
if ((name == null) || (observers[i].Name == name))
{
return (T)observers[i];
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void Test02_TestGetMixedRealityInputSystem()
TestUtilities.InitializeMixedRealityToolkitScene(true);

// Retrieve Input System
var inputSystem = MixedRealityToolkit.Instance.GetService<IMixedRealityInputSystem>();
IMixedRealityInputSystem inputSystem = null;
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);

// Tests
Assert.IsNotNull(inputSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public IEnumerator TestGazeCursorArticulated()

// raise hand up -- gaze cursor should no longer be visible
// disable user input
InputSimulationService inputSimulationService = MixedRealityToolkit.Instance.GetService<InputSimulationService>();
InputSimulationService inputSimulationService = (inputSystem as IMixedRealityDataProviderAccess).GetDataProvider<InputSimulationService>();
Assert.IsNotNull(inputSimulationService, "InputSimulationService is null!");

inputSimulationService.UserInputEnabled = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ public MixedRealityGesturesProfile GesturesProfile
internal set { gesturesProfile = value; }
}


private IMixedRealitySpeechSystem speechSystem;

/// <summary>
/// Current Registered Speech System.
/// </summary>
public IMixedRealitySpeechSystem SpeechSystem => speechSystem ?? (speechSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySpeechSystem>());

/// <summary>
/// The list of cultures where speech recognition is supported
/// </summary>
Expand Down Expand Up @@ -130,11 +122,6 @@ public bool IsSpeechSupported
}
}

/// <summary>
/// Is the speech Commands Enabled?
/// </summary>
public bool IsSpeechCommandsEnabled => speechCommandsProfile != null && SpeechSystem != null && MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled;

[SerializeField]
[Tooltip("Speech Command profile for wiring up Voice Input to Actions.")]
private MixedRealitySpeechCommandsProfile speechCommandsProfile;
Expand All @@ -148,18 +135,6 @@ public MixedRealitySpeechCommandsProfile SpeechCommandsProfile
internal set { speechCommandsProfile = value; }
}

private IMixedRealityDictationSystem dictationSystem;

/// <summary>
/// Current Registered Dictation System.
/// </summary>
public IMixedRealityDictationSystem DictationSystem => dictationSystem ?? (dictationSystem = MixedRealityToolkit.Instance.GetService<IMixedRealityDictationSystem>());

/// <summary>
/// Is Dictation Enabled?
/// </summary>
public bool IsDictationEnabled => MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled && DictationSystem != null;

[SerializeField]
[Tooltip("Enable and configure the devices for your application.")]
private bool enableControllerMapping = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace Microsoft.MixedReality.Toolkit.Input
/// <summary>
/// Provides eye tracking information.
/// </summary>
public interface IMixedRealityEyeGazeDataProvider : IMixedRealityDataProvider
public interface IMixedRealityEyeGazeDataProvider : IMixedRealityInputDeviceManager
{
IMixedRealityEyeSaccadeProvider SaccadeProvider { get; }

bool SmoothEyeTracking { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using Microsoft.MixedReality.Toolkit.Input;

/// <summary>
/// Interface defining a mouse input device manager.
/// </summary>
public interface IMixedRealityMouseDeviceManager : IMixedRealityInputDeviceManager
{
/// <summary>
/// Typed representation of the ConfigurationProfile property.
/// </summary>
MixedRealityMouseInputProfile MouseInputProfile { get; }
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 83bf0cc

Please sign in to comment.