Skip to content

Commit 285b4e5

Browse files
committed
Implementing GetActiveControllers for InputSimulationService so that the list of simulated controllers can be queried while testing in the editor.
1 parent d9b1f34 commit 285b4e5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Assets/MixedRealityToolkit.Services/InputSimulation/InputSimulationService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.MixedReality.Toolkit.Utilities;
55
using System;
66
using System.Collections.Generic;
7+
using System.Linq;
78
using UnityEngine;
89

910
namespace Microsoft.MixedReality.Toolkit.Input
@@ -32,6 +33,11 @@ public class InputSimulationService : BaseInputDeviceManager
3233
/// </summary>
3334
private readonly Dictionary<Handedness, SimulatedHand> trackedHands = new Dictionary<Handedness, SimulatedHand>();
3435

36+
/// <summary>
37+
/// Active controllers
38+
/// </summary>
39+
private IMixedRealityController[] activeControllers = new IMixedRealityController[0];
40+
3541
/// <summary>
3642
/// Timestamp of the last hand device update
3743
/// </summary>
@@ -50,6 +56,12 @@ public InputSimulationService(
5056
{
5157
}
5258

59+
/// <inheritdoc />
60+
public override IMixedRealityController[] GetActiveControllers()
61+
{
62+
return activeControllers;
63+
}
64+
5365
/// <inheritdoc />
5466
public override void Initialize()
5567
{
@@ -273,6 +285,7 @@ private SimulatedHand GetOrAddHandDevice(Handedness handedness, HandSimulationMo
273285
MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller);
274286

275287
trackedHands.Add(handedness, controller);
288+
UpdateActiveControllers();
276289

277290
return controller;
278291
}
@@ -285,6 +298,7 @@ private void RemoveHandDevice(Handedness handedness)
285298
MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
286299

287300
trackedHands.Remove(handedness);
301+
UpdateActiveControllers();
288302
}
289303
}
290304

@@ -295,6 +309,12 @@ private void RemoveAllHandDevices()
295309
MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
296310
}
297311
trackedHands.Clear();
312+
UpdateActiveControllers();
313+
}
314+
315+
private void UpdateActiveControllers()
316+
{
317+
activeControllers = trackedHands.Values.ToArray<IMixedRealityController>();
298318
}
299319
}
300320
}

0 commit comments

Comments
 (0)