diff --git a/Controllers/WindowsMixedRealityController.cs b/Controllers/WindowsMixedRealityController.cs index 610ed7b..e5845ac 100644 --- a/Controllers/WindowsMixedRealityController.cs +++ b/Controllers/WindowsMixedRealityController.cs @@ -4,6 +4,7 @@ using XRTK.Definitions.Devices; using XRTK.Definitions.InputSystem; using XRTK.Definitions.Utilities; +using XRTK.Extensions; using XRTK.Interfaces.InputSystem; using XRTK.Providers.Controllers; @@ -94,49 +95,55 @@ public void UpdateController(InteractionSourceState interactionSourceState) { if (!Enabled) { return; } + base.UpdateController(); + UpdateControllerData(interactionSourceState); if (Interactions == null) { - Debug.LogError($"No interaction configuration for Windows Mixed Reality Motion Controller {ControllerHandedness}"); + Debug.LogError($"No interaction configuration for {GetType().Name} {ControllerHandedness}"); Enabled = false; } for (int i = 0; i < Interactions?.Length; i++) { - switch (Interactions[i].InputType) + var interactionMapping = Interactions[i]; + + switch (interactionMapping.InputType) { case DeviceInputType.None: break; case DeviceInputType.SpatialPointer: - UpdatePointerData(interactionSourceState, Interactions[i]); + UpdatePointerData(interactionSourceState, interactionMapping); break; case DeviceInputType.Select: case DeviceInputType.Trigger: case DeviceInputType.TriggerTouch: case DeviceInputType.TriggerPress: - UpdateTriggerData(interactionSourceState, Interactions[i]); + UpdateTriggerData(interactionSourceState, interactionMapping); break; case DeviceInputType.SpatialGrip: - UpdateGripData(interactionSourceState, Interactions[i]); + UpdateGripData(interactionSourceState, interactionMapping); break; case DeviceInputType.ThumbStick: case DeviceInputType.ThumbStickPress: - UpdateThumbStickData(interactionSourceState, Interactions[i]); + UpdateThumbStickData(interactionSourceState, interactionMapping); break; case DeviceInputType.Touchpad: case DeviceInputType.TouchpadTouch: case DeviceInputType.TouchpadPress: - UpdateTouchPadData(interactionSourceState, Interactions[i]); + UpdateTouchPadData(interactionSourceState, interactionMapping); break; case DeviceInputType.Menu: - UpdateMenuData(interactionSourceState, Interactions[i]); + UpdateMenuData(interactionSourceState, interactionMapping); break; default: - Debug.LogError($"Input [{Interactions[i].InputType}] is not handled for this controller [WindowsMixedRealityController]"); + Debug.LogError($"Input [{interactionMapping.InputType}] is not handled for this controller [{GetType().Name}]"); Enabled = false; break; } + + interactionMapping.RaiseInputAction(InputSource, ControllerHandedness); } LastSourceStateReading = interactionSourceState; @@ -219,15 +226,7 @@ private void UpdatePointerData(InteractionSourceState interactionSourceState, Mi currentPointerPose.Position = currentPointerPosition; currentPointerPose.Rotation = currentPointerRotation; - // Update the interaction data source interactionMapping.PoseData = currentPointerPose; - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - // Raise input system Event if it enabled - MixedRealityToolkit.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, currentPointerPose); - } } /// @@ -255,15 +254,7 @@ private void UpdateGripData(InteractionSourceState interactionSourceState, Mixed currentGripPose.Rotation = currentGripRotation; } - // Update the interaction data source interactionMapping.PoseData = currentGripPose; - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - // Raise input system Event if it enabled - MixedRealityToolkit.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, currentGripPose); - } } break; } @@ -280,67 +271,17 @@ private void UpdateTouchPadData(InteractionSourceState interactionSourceState, M { case DeviceInputType.TouchpadTouch: { - // Update the interaction data source interactionMapping.BoolData = interactionSourceState.touchpadTouched; - - // If our value changed raise it. - if (interactionMapping.Changed) - { - // Raise input system Event if it enabled - if (interactionSourceState.touchpadTouched) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - else - { - MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - } - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } break; } case DeviceInputType.TouchpadPress: { - //Update the interaction data source interactionMapping.BoolData = interactionSourceState.touchpadPressed; - - // If our value changed raise it. - if (interactionMapping.Changed) - { - // Raise input system Event if it enabled - if (interactionSourceState.touchpadPressed) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - else - { - MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - } - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } break; } case DeviceInputType.Touchpad: { - // Update the interaction data source interactionMapping.Vector2Data = interactionSourceState.touchpadPosition; - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - // Raise input system Event if it enabled - MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.touchpadPosition); - } break; } } @@ -357,41 +298,12 @@ private void UpdateThumbStickData(InteractionSourceState interactionSourceState, { case DeviceInputType.ThumbStickPress: { - // Update the interaction data source interactionMapping.BoolData = interactionSourceState.thumbstickPressed; - - // If our value changed raise it. - if (interactionMapping.Changed) - { - // Raise input system Event if it enabled - if (interactionSourceState.thumbstickPressed) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - else - { - MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - } - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } break; } case DeviceInputType.ThumbStick: { - // Update the interaction data source interactionMapping.Vector2Data = interactionSourceState.thumbstickPosition; - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - // Raise input system Event if it enabled - MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.thumbstickPosition); - } break; } } @@ -407,28 +319,7 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi switch (interactionMapping.InputType) { case DeviceInputType.TriggerPress: - //Update the interaction data source interactionMapping.BoolData = interactionSourceState.grasped; - - // If our value changed raise it. - if (interactionMapping.Changed) - { - // Raise input system Event if it enabled - if (interactionMapping.BoolData) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - else - { - MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - } - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } break; case DeviceInputType.Select: { @@ -456,66 +347,16 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi // END WORKAROUND: Unity issue #1033526 interactionMapping.BoolData = selectPressed; - - // If our value changed raise it. - if (interactionMapping.Changed) - { - // Raise input system Event if it enabled - if (interactionMapping.BoolData) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - else - { - MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - } - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } break; } case DeviceInputType.Trigger: { - // Update the interaction data source interactionMapping.FloatData = interactionSourceState.selectPressedAmount; - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - // Raise input system Event if it enabled - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.selectPressedAmount); - } break; } case DeviceInputType.TriggerTouch: { - // Update the interaction data source interactionMapping.BoolData = interactionSourceState.selectPressedAmount > 0; - - // If our value changed raise it. - if (interactionMapping.Changed) - { - // Raise input system Event if it enabled - if (interactionSourceState.selectPressedAmount > 0) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - else - { - MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - } - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - // Raise input system Event if it enabled - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionSourceState.selectPressedAmount); - } break; } } @@ -528,28 +369,7 @@ private void UpdateTriggerData(InteractionSourceState interactionSourceState, Mi /// private void UpdateMenuData(InteractionSourceState interactionSourceState, MixedRealityInteractionMapping interactionMapping) { - //Update the interaction data source interactionMapping.BoolData = interactionSourceState.menuPressed; - - // If our value changed raise it. - if (interactionMapping.Changed) - { - // Raise input system Event if it enabled - if (interactionMapping.BoolData) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - else - { - MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } - } - - // If our value was updated, raise it. - if (interactionMapping.Updated) - { - MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction); - } } #endregion Update data functions diff --git a/Controllers/WindowsMixedRealityDataProvider.cs b/Controllers/WindowsMixedRealityDataProvider.cs index f6de9de..bc43f83 100644 --- a/Controllers/WindowsMixedRealityDataProvider.cs +++ b/Controllers/WindowsMixedRealityDataProvider.cs @@ -6,7 +6,6 @@ #if UNITY_WSA using System.Collections.Generic; -using System.Linq; using UnityEngine; using UnityEngine.XR.WSA.Input; using XRTK.Definitions.Devices; @@ -80,9 +79,6 @@ public WindowsMixedRealityDataProvider(string name, uint priority, WindowsMixedR /// public InteractionSourceState[] LastInteractionManagerStateReading { get; protected set; } - /// - public override IMixedRealityController[] GetActiveControllers() => activeControllers.Values.ToArray(); - private static bool gestureRecognizerEnabled; /// @@ -373,7 +369,7 @@ public override void Disable() for (var i = 0; i < states.Length; i++) { - RemoveController(states[i]); + RemoveController(states[i], false); } } @@ -441,6 +437,7 @@ private WindowsMixedRealityController GetController(InteractionSource interactio } activeControllers.Add(interactionSource.id, detectedController); + AddController(detectedController); return detectedController; } @@ -500,16 +497,20 @@ async void DispatchedHandler() /// Remove the selected controller from the Active Store /// /// Source State provided by the SDK to remove - private void RemoveController(InteractionSourceState interactionSourceState) + private void RemoveController(InteractionSourceState interactionSourceState, bool clearFromRegistry = true) { var controller = GetController(interactionSourceState.source); if (controller != null) { MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller); + RemoveController(controller); } - activeControllers.Remove(interactionSourceState.source.id); + if (clearFromRegistry) + { + activeControllers.Remove(interactionSourceState.source.id); + } } #endregion Controller Utilities diff --git a/package.json b/package.json index 6872407..65cc0b3 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,12 @@ "mixed", "reality" ], - "version": "0.1.6", + "version": "0.1.7", "unity": "2019.1", "license": "MIT", "author": "XRTK Team (https://github.com/XRTK)", "dependencies": { - "com.xrtk.core": "0.1.20", + "com.xrtk.core": "0.1.21", "com.unity.xr.windowsmr.metro": "1.0.14" } } \ No newline at end of file