Skip to content

Commit 102d1c3

Browse files
committed
Update ControllerFinder with new Visualizer pattern
1 parent 18e0bb4 commit 102d1c3

File tree

3 files changed

+8
-36
lines changed

3 files changed

+8
-36
lines changed

Assets/MixedRealityToolkit-SDK/Features/Utilities/Solvers/ControllerFinder.cs

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33

44
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
55
using Microsoft.MixedReality.Toolkit.Core.EventDatum.Input;
6-
using Microsoft.MixedReality.Toolkit.Core.Interfaces;
76
using Microsoft.MixedReality.Toolkit.Core.Interfaces.Devices;
87
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem.Handlers;
98
using Microsoft.MixedReality.Toolkit.Core.Managers;
10-
using System.Collections.Generic;
119
using UnityEngine;
1210

1311
namespace Microsoft.MixedReality.Toolkit.SDK.Utilities.Solvers
@@ -43,19 +41,10 @@ public Handedness Handedness
4341
/// </summary>
4442
protected Transform ControllerTransform;
4543

46-
private IEnumerable<IMixedRealityManager> BaseDeviceManagers => baseDeviceManagers ?? (baseDeviceManagers = MixedRealityManager.Instance.GetManagers(typeof(IMixedRealityDeviceManager)));
47-
private IEnumerable<IMixedRealityManager> baseDeviceManagers = null;
48-
4944
#region MonoBehaviour Implementation
5045

5146
protected virtual void OnEnable()
5247
{
53-
if (BaseDeviceManagers == null)
54-
{
55-
// The base device manager has not been set up yet.
56-
return;
57-
}
58-
5948
// Look if the controller has loaded.
6049
RefreshControllerTransform();
6150
}
@@ -89,24 +78,18 @@ protected virtual void TryAndAddControllerTransform()
8978
{
9079
// Look if the controller was already loaded. This could happen if the
9180
// GameObject was instantiated at runtime and the model loaded event has already fired.
92-
if (BaseDeviceManagers == null)
81+
if (MixedRealityManager.InputSystem == null)
9382
{
94-
// The BaseDeviceManager could not be found.
83+
// The InputSystem could not be found.
9584
return;
9685
}
9786

98-
foreach (IMixedRealityDeviceManager manager in BaseDeviceManagers)
87+
foreach (IMixedRealityController controller in MixedRealityManager.InputSystem.DetectedControllers)
9988
{
100-
IMixedRealityController[] controllers = manager.GetActiveControllers();
101-
102-
for (int i = 0; i < controllers.Length; i++)
89+
if (controller.ControllerHandedness == handedness)
10390
{
104-
if (controllers[i].ControllerHandedness == handedness)
105-
{
106-
AddControllerTransform(controllers[i]);
107-
return;
108-
}
109-
91+
AddControllerTransform(controller);
92+
return;
11093
}
11194
}
11295
}
@@ -117,9 +100,9 @@ protected virtual void TryAndAddControllerTransform()
117100
/// <param name="newController">The new controller to be tracked.</param>
118101
protected virtual void AddControllerTransform(IMixedRealityController newController)
119102
{
120-
if (newController.ControllerHandedness == handedness && newController.Transform != null && !newController.Transform.Equals(ControllerTransform))
103+
if (newController.ControllerHandedness == handedness && newController.Visualizer.GameObjectProxy.transform != null && !newController.Visualizer.GameObjectProxy.transform.Equals(ControllerTransform))
121104
{
122-
ControllerTransform = newController.Transform;
105+
ControllerTransform = newController.Visualizer.GameObjectProxy.transform;
123106

124107
OnControllerFound();
125108
}

Assets/MixedRealityToolkit/_Core/Devices/BaseController.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ protected BaseController(TrackingState trackingState, Handedness controllerHande
8181
/// <inheritdoc />
8282
public MixedRealityInteractionMapping[] Interactions { get; private set; } = null;
8383

84-
/// <inheritdoc />
85-
public Transform Transform { get; protected set; }
86-
8784
#endregion IMixedRealityController Implementation
8885

8986
/// <summary>
@@ -204,8 +201,6 @@ private void TryRenderControllerModel(Type controllerType)
204201
{
205202
Debug.LogError($"{controllerObject.name} is missing a IMixedRealityControllerVisualizer component!");
206203
}
207-
208-
Transform = controllerObject.transform;
209204
}
210205
}
211206
}

Assets/MixedRealityToolkit/_Core/Interfaces/Devices/IMixedRealityController.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Microsoft.MixedReality.Toolkit.Core.Definitions.Devices;
55
using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities;
66
using Microsoft.MixedReality.Toolkit.Core.Interfaces.InputSystem;
7-
using UnityEngine;
87

98
namespace Microsoft.MixedReality.Toolkit.Core.Interfaces.Devices
109
{
@@ -65,10 +64,5 @@ public interface IMixedRealityController
6564
/// Mapping definition for this controller, linking the Physical inputs to logical Input System Actions
6665
/// </summary>
6766
MixedRealityInteractionMapping[] Interactions { get; }
68-
69-
/// <summary>
70-
/// The transform of this controller, used for tracking and observing the controller if it's tracked.
71-
/// </summary>
72-
Transform Transform { get; }
7367
}
7468
}

0 commit comments

Comments
 (0)