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, IInputSimulationSe
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 {
@@ -276,6 +288,7 @@ private SimulatedHand GetOrAddHandDevice(Handedness handedness, HandSimulationMo
276288 MixedRealityToolkit . InputSystem ? . RaiseSourceDetected ( controller . InputSource , controller ) ;
277289
278290 trackedHands . Add ( handedness , controller ) ;
291+ UpdateActiveControllers ( ) ;
279292
280293 return controller ;
281294 }
@@ -288,6 +301,7 @@ private void RemoveHandDevice(Handedness handedness)
288301 MixedRealityToolkit . InputSystem ? . RaiseSourceLost ( controller . InputSource , controller ) ;
289302
290303 trackedHands . Remove ( handedness ) ;
304+ UpdateActiveControllers ( ) ;
291305 }
292306 }
293307
@@ -298,6 +312,12 @@ private void RemoveAllHandDevices()
298312 MixedRealityToolkit . InputSystem ? . RaiseSourceLost ( controller . InputSource , controller ) ;
299313 }
300314 trackedHands . Clear ( ) ;
315+ UpdateActiveControllers ( ) ;
316+ }
317+
318+ private void UpdateActiveControllers ( )
319+ {
320+ activeControllers = trackedHands . Values . ToArray < IMixedRealityController > ( ) ;
301321 }
302322 }
303323}
0 commit comments