Skip to content

Commit ba105bf

Browse files
author
David Kline
authored
Merge pull request #3963 from djohnsomsft/inputsimulation_activecontrollers
Add GetActiveControllers implementation to InputSimulationService
2 parents 2963154 + 6b4a739 commit ba105bf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Assets/MixedRealityToolkit.Services/InputSimulation/Editor/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, 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

Comments
 (0)