Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Dev/remove core system accessors (#123)
Browse files Browse the repository at this point in the history
* removed the core system accessors from the xrtk service locator

* updated core system accessors

* updated core access usage

* updated core accessors that were hidden by compiler symbol

* bumped version numbers

* updated packages

updated unity editor to 2019.4.19f1

* updated package info

* reverted change
  • Loading branch information
StephenHodgson authored Feb 9, 2021
1 parent c825526 commit 89b8b09
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ public class WindowsMixedRealityBoundaryDataProvider : BaseDataProvider, IMixedR
public WindowsMixedRealityBoundaryDataProvider(string name, uint priority, BaseMixedRealityProfile profile, IMixedRealityBoundarySystem parentService)
: base(name, priority, profile, parentService)
{
boundarySystem = parentService;
}

private readonly IMixedRealityBoundarySystem boundarySystem;

/// <inheritdoc />
public override void Enable()
{
base.Enable();

MixedRealityToolkit.BoundarySystem.SetupBoundary(this);
boundarySystem.SetupBoundary(this);
}

#region IMixedRealityBoundaryDataProvider Implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,26 @@ public WindowsMixedRealityControllerDataProvider(string name, uint priority, Win
: base(name, priority, profile, parentService)
{
#if UNITY_WSA
this.profile = profile;
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealityInputSystem, MixedRealityInputSystemProfile>(out var inputSystemProfile))
{
gestures = inputSystemProfile.GesturesProfile.Gestures;
}

gestureAutoStartBehavior = profile.WindowsGestureAutoStart;
GestureSettings = profile.ManipulationGestures;
NavigationSettings = profile.NavigationGestures;
RailsNavigationSettings = profile.RailsNavigationGestures;
UseRailsNavigation = profile.UseRailsNavigation;
gestureRecognizer = new GestureRecognizer();
navigationGestureRecognizer = new GestureRecognizer();
#endif // UNITY_WSA
}

#if UNITY_WSA

private readonly WindowsMixedRealityControllerDataProviderProfile profile;
private readonly AutoStartBehavior gestureAutoStartBehavior;

private readonly MixedRealityGestureMapping[] gestures;

/// <summary>
/// The max expected sources is two - two controllers and/or two hands.
Expand Down Expand Up @@ -250,37 +261,27 @@ public override void Enable()
navigationGestureRecognizer.NavigationCompleted += NavigationGestureRecognizer_NavigationCompleted;
navigationGestureRecognizer.NavigationCanceled += NavigationGestureRecognizer_NavigationCanceled;

if (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.GesturesProfile != null)
for (int i = 0; i < gestures?.Length; i++)
{
var gestureProfile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.GesturesProfile;
GestureSettings = profile.ManipulationGestures;
NavigationSettings = profile.NavigationGestures;
RailsNavigationSettings = profile.RailsNavigationGestures;
UseRailsNavigation = profile.UseRailsNavigation;
var gesture = gestures[i];

for (int i = 0; i < gestureProfile.Gestures.Length; i++)
switch (gesture.GestureType)
{
var gesture = gestureProfile.Gestures[i];

switch (gesture.GestureType)
{
case GestureInputType.Hold:
holdAction = gesture.Action;
break;
case GestureInputType.Manipulation:
manipulationAction = gesture.Action;
break;
case GestureInputType.Navigation:
navigationAction = gesture.Action;
break;
case GestureInputType.Tap:
tapAction = gesture.Action;
break;
case GestureInputType.DoubleTap:
doubleTapAction = gesture.Action;
break;
}
case GestureInputType.Hold:
holdAction = gesture.Action;
break;
case GestureInputType.Manipulation:
manipulationAction = gesture.Action;
break;
case GestureInputType.Navigation:
navigationAction = gesture.Action;
break;
case GestureInputType.Tap:
tapAction = gesture.Action;
break;
case GestureInputType.DoubleTap:
doubleTapAction = gesture.Action;
break;
}
}

Expand All @@ -300,14 +301,13 @@ public override void Enable()

if (controller != null)
{
MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
controller.UpdateController(state);
}
}

if (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.GesturesProfile != null &&
profile.WindowsGestureAutoStart == AutoStartBehavior.AutoStart)
if (gestures != null &&
gestureAutoStartBehavior == AutoStartBehavior.AutoStart)
{
GestureRecognizerEnabled = true;
}
Expand All @@ -329,7 +329,7 @@ public override void Update()

if (controller != null && raiseSourceDetected)
{
MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
}

controller?.UpdateController(state);
Expand Down Expand Up @@ -511,7 +511,7 @@ private void RemoveController(InteractionSourceState interactionSourceState, boo

if (controller != null)
{
MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
InputSystem?.RaiseSourceLost(controller.InputSource, controller);
}

if (clearFromRegistry)
Expand Down Expand Up @@ -541,7 +541,7 @@ private void InteractionManager_InteractionSourceDetected(InteractionSourceDetec

if (controller != null && raiseSourceDetected)
{
MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
}

controller?.UpdateController(args.state);
Expand All @@ -568,13 +568,13 @@ private void GestureRecognizer_Tapped(TappedEventArgs args)
{
if (args.tapCount == 1)
{
MixedRealityToolkit.InputSystem?.RaiseGestureStarted(controller, tapAction);
MixedRealityToolkit.InputSystem?.RaiseGestureCompleted(controller, tapAction);
InputSystem?.RaiseGestureStarted(controller, tapAction);
InputSystem?.RaiseGestureCompleted(controller, tapAction);
}
else if (args.tapCount == 2)
{
MixedRealityToolkit.InputSystem?.RaiseGestureStarted(controller, doubleTapAction);
MixedRealityToolkit.InputSystem?.RaiseGestureCompleted(controller, doubleTapAction);
InputSystem?.RaiseGestureStarted(controller, doubleTapAction);
InputSystem?.RaiseGestureCompleted(controller, doubleTapAction);
}
}
}
Expand All @@ -584,7 +584,7 @@ private void GestureRecognizer_HoldStarted(HoldStartedEventArgs args)
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem?.RaiseGestureStarted(controller, holdAction);
InputSystem?.RaiseGestureStarted(controller, holdAction);
}
}

Expand All @@ -593,7 +593,7 @@ private void GestureRecognizer_HoldCompleted(HoldCompletedEventArgs args)
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCompleted(controller, holdAction);
InputSystem.RaiseGestureCompleted(controller, holdAction);
}
}

Expand All @@ -602,7 +602,7 @@ private void GestureRecognizer_HoldCanceled(HoldCanceledEventArgs args)
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCanceled(controller, holdAction);
InputSystem.RaiseGestureCanceled(controller, holdAction);
}
}

Expand All @@ -611,7 +611,7 @@ private void GestureRecognizer_ManipulationStarted(ManipulationStartedEventArgs
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureStarted(controller, manipulationAction);
InputSystem.RaiseGestureStarted(controller, manipulationAction);
}
}

Expand All @@ -620,7 +620,7 @@ private void GestureRecognizer_ManipulationUpdated(ManipulationUpdatedEventArgs
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureUpdated(controller, manipulationAction, args.cumulativeDelta);
InputSystem.RaiseGestureUpdated(controller, manipulationAction, args.cumulativeDelta);
}
}

Expand All @@ -629,7 +629,7 @@ private void GestureRecognizer_ManipulationCompleted(ManipulationCompletedEventA
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCompleted(controller, manipulationAction, args.cumulativeDelta);
InputSystem.RaiseGestureCompleted(controller, manipulationAction, args.cumulativeDelta);
}
}

Expand All @@ -638,7 +638,7 @@ private void GestureRecognizer_ManipulationCanceled(ManipulationCanceledEventArg
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCanceled(controller, manipulationAction);
InputSystem.RaiseGestureCanceled(controller, manipulationAction);
}
}

Expand All @@ -651,7 +651,7 @@ private void NavigationGestureRecognizer_NavigationStarted(NavigationStartedEven
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureStarted(controller, navigationAction);
InputSystem.RaiseGestureStarted(controller, navigationAction);
}
}

Expand All @@ -660,7 +660,7 @@ private void NavigationGestureRecognizer_NavigationUpdated(NavigationUpdatedEven
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureUpdated(controller, navigationAction, args.normalizedOffset);
InputSystem.RaiseGestureUpdated(controller, navigationAction, args.normalizedOffset);
}
}

Expand All @@ -669,7 +669,7 @@ private void NavigationGestureRecognizer_NavigationCompleted(NavigationCompleted
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCompleted(controller, navigationAction, args.normalizedOffset);
InputSystem.RaiseGestureCompleted(controller, navigationAction, args.normalizedOffset);
}
}

Expand All @@ -678,7 +678,7 @@ private void NavigationGestureRecognizer_NavigationCanceled(NavigationCanceledEv
var controller = GetController(args.source);
if (controller != null)
{
MixedRealityToolkit.InputSystem.RaiseGestureCanceled(controller, navigationAction);
InputSystem.RaiseGestureCanceled(controller, navigationAction);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using XRTK.Services;
using XRTK.Attributes;
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.Platforms;
using XRTK.Interfaces.InputSystem;
using XRTK.Providers.Controllers.Hands;
Expand Down Expand Up @@ -39,12 +40,16 @@ public class WindowsMixedRealityHandControllerDataProvider : BaseHandControllerD
public WindowsMixedRealityHandControllerDataProvider(string name, uint priority, WindowsMixedRealityHandControllerDataProviderProfile profile, IMixedRealityInputSystem parentService)
: base(name, priority, profile, parentService)
{
if (!MixedRealityToolkit.TryGetSystemProfile<IMixedRealityInputSystem, MixedRealityInputSystemProfile>(out var inputSystemProfile))
{
throw new ArgumentException($"Unable to get a valid {nameof(MixedRealityInputSystemProfile)}!");
}

handDataProvider = new WindowsMixedRealityHandDataConverter();

var globalSettingsProfile = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile;
var isGrippingThreshold = profile.GripThreshold != globalSettingsProfile.GripThreshold
var isGrippingThreshold = profile.GripThreshold != inputSystemProfile.GripThreshold
? profile.GripThreshold
: globalSettingsProfile.GripThreshold;
: inputSystemProfile.GripThreshold;

postProcessor = new HandDataPostProcessor(TrackedPoses, isGrippingThreshold)
{
Expand Down Expand Up @@ -226,7 +231,7 @@ private MixedRealityHandController CreateController(SpatialInteractionSource spa
detectedController.InputSource.Pointers[i].Controller = detectedController;
}

MixedRealityToolkit.InputSystem?.RaiseSourceDetected(detectedController.InputSource, detectedController);
InputSystem?.RaiseSourceDetected(detectedController.InputSource, detectedController);

detectedController.TryRenderControllerModel();

Expand All @@ -239,7 +244,7 @@ private void RemoveController(Handedness handedness, bool removeFromRegistry = t
{
if (TryGetController(handedness, out var controller))
{
MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
InputSystem?.RaiseSourceLost(controller.InputSource, controller);

if (removeFromRegistry)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
using XRTK.Definitions.Controllers;
using XRTK.Definitions.Devices;
using XRTK.Definitions.Utilities;
using XRTK.Interfaces.CameraSystem;
using XRTK.Interfaces.Providers.Controllers;
using XRTK.Providers.Controllers;

using XRTK.Utilities;
#if UNITY_WSA
using UnityEngine;
using UnityEngine.XR.WSA.Input;
Expand Down Expand Up @@ -200,22 +201,22 @@ private void UpdateControllerData(InteractionSourceState interactionSourceState)
// Raise input system events if it is enabled.
if (lastState != TrackingState)
{
MixedRealityToolkit.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
}

if (TrackingState == TrackingState.Tracked && lastControllerPose != currentControllerPose)
{
if (IsPositionAvailable && IsRotationAvailable)
{
MixedRealityToolkit.InputSystem?.RaiseSourcePoseChanged(InputSource, this, currentControllerPose);
InputSystem?.RaiseSourcePoseChanged(InputSource, this, currentControllerPose);
}
else if (IsPositionAvailable && !IsRotationAvailable)
{
MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, currentControllerPosition);
InputSystem?.RaiseSourcePositionChanged(InputSource, this, currentControllerPosition);
}
else if (!IsPositionAvailable && IsRotationAvailable)
{
MixedRealityToolkit.InputSystem?.RaiseSourceRotationChanged(InputSource, this, currentControllerRotation);
InputSystem?.RaiseSourceRotationChanged(InputSource, this, currentControllerRotation);
}
}
}
Expand Down Expand Up @@ -249,15 +250,10 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed
interactionSourceState.sourcePose.TryGetPosition(out currentGripPosition, InteractionSourceNode.Grip);
interactionSourceState.sourcePose.TryGetRotation(out currentGripRotation);

var cameraRig = MixedRealityToolkit.CameraSystem?.MainCameraRig;

if (cameraRig != null &&
cameraRig.PlayspaceTransform != null)
if (MixedRealityToolkit.TryGetSystem<IMixedRealityCameraSystem>(out var cameraSystem))
{
currentGripPose.Position = cameraRig.PlayspaceTransform.TransformPoint(currentGripPosition);
currentGripPose.Rotation =
Quaternion.Euler(
cameraRig.PlayspaceTransform.TransformDirection(currentGripRotation.eulerAngles));
currentGripPose.Position = cameraSystem.MainCameraRig.PlayspaceTransform.TransformPoint(currentGripPosition);
currentGripPose.Rotation = Quaternion.Euler(cameraSystem.MainCameraRig.PlayspaceTransform.TransformDirection(currentGripRotation.eulerAngles));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using UnityEngine.XR.WSA;
using XRTK.Definitions.SpatialAwarenessSystem;
using XRTK.Extensions;
using XRTK.Interfaces.CameraSystem;
using XRTK.Services;
using XRTK.Utilities;
#endif // UNITY_WSA
Expand Down Expand Up @@ -64,8 +65,8 @@ public override void Update()
// Update the observer location if it is not stationary
if (!IsStationaryObserver)
{
ObserverOrigin = MixedRealityToolkit.CameraSystem != null
? MixedRealityToolkit.CameraSystem.MainCameraRig.CameraTransform.localPosition
ObserverOrigin = MixedRealityToolkit.TryGetSystem<IMixedRealityCameraSystem>(out var cameraSystem)
? cameraSystem.MainCameraRig.CameraTransform.localPosition
: CameraCache.Main.transform.position;
}

Expand Down
Loading

0 comments on commit 89b8b09

Please sign in to comment.