44using Microsoft . MixedReality . Toolkit . Utilities ;
55using System ;
66using System . Collections . Generic ;
7+ using System . Linq ;
78using UnityEngine ;
89
910namespace 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