Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Ensure that the detected input sources and detected controller's are readonly from the system #481

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public interface IMixedRealityInputSystem : IMixedRealityEventSystem
/// <summary>
/// List of the Interaction Input Sources as detected by the input manager like hands or motion controllers.
/// </summary>
HashSet<IMixedRealityInputSource> DetectedInputSources { get; }
IReadOnlyCollection<IMixedRealityInputSource> DetectedInputSources { get; }

/// <summary>
/// List of <see cref="IMixedRealityController"/>s currently detected by the input manager.
/// </summary>
/// <remarks>
/// This property is similar to <see cref="DetectedInputSources"/>, as this is a subset of those <see cref="IMixedRealityInputSource"/>s in that list.
/// </remarks>
HashSet<IMixedRealityController> DetectedControllers { get; }
IReadOnlyCollection<IMixedRealityController> DetectedControllers { get; }

/// <summary>
/// The current Focus Provider that's been implemented by this Input System.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ public MixedRealityInputSystem(MixedRealityInputSystemProfile profile) : base(pr
/// <inheritdoc />
public event Action InputDisabled;

private readonly HashSet<IMixedRealityInputSource> detectedInputSources = new HashSet<IMixedRealityInputSource>();

/// <inheritdoc />
public HashSet<IMixedRealityInputSource> DetectedInputSources { get; } = new HashSet<IMixedRealityInputSource>();
public IReadOnlyCollection<IMixedRealityInputSource> DetectedInputSources => detectedInputSources;

private readonly HashSet<IMixedRealityController> detectedControllers = new HashSet<IMixedRealityController>();

/// <inheritdoc />
public HashSet<IMixedRealityController> DetectedControllers { get; } = new HashSet<IMixedRealityController>();
public IReadOnlyCollection<IMixedRealityController> DetectedControllers => detectedControllers;

private IMixedRealityFocusProvider focusProvider = null;

Expand Down Expand Up @@ -376,7 +380,7 @@ public void PushInputDisable()
}

/// <summary>
/// Pop disabled input state. When the last disabled state is
/// Pop disabled input state. When the last disabled state is
/// popped off the stack input will be re-enabled.
/// </summary>
public void PopInputDisable()
Expand Down Expand Up @@ -485,7 +489,7 @@ public void ClearFallbackInputStack()
/// <inheritdoc />
public bool TryGetController(IMixedRealityInputSource inputSource, out IMixedRealityController controller)
{
foreach (var mixedRealityController in DetectedControllers)
foreach (var mixedRealityController in detectedControllers)
{
if (inputSource.SourceId == mixedRealityController.InputSource.SourceId)
{
Expand All @@ -512,7 +516,7 @@ public uint GenerateNewSourceId()
{
var newId = (uint)UnityEngine.Random.Range(1, int.MaxValue);

foreach (var inputSource in DetectedInputSources)
foreach (var inputSource in detectedInputSources)
{
if (inputSource.SourceId == newId)
{
Expand All @@ -534,13 +538,13 @@ public void RaiseSourceDetected(IMixedRealityInputSource source, IMixedRealityCo
// Create input event
sourceStateEventData.Initialize(source, controller);

Debug.Assert(!DetectedInputSources.Contains(source), $"{source.SourceName} has already been registered with the Input Manager!");
Debug.Assert(!detectedInputSources.Contains(source), $"{source.SourceName} has already been registered with the Input Manager!");

DetectedInputSources.Add(source);
detectedInputSources.Add(source);

if (controller != null)
{
DetectedControllers.Add(controller);
detectedControllers.Add(controller);
}

FocusProvider?.OnSourceDetected(sourceStateEventData);
Expand All @@ -562,13 +566,13 @@ public void RaiseSourceLost(IMixedRealityInputSource source, IMixedRealityContro
// Create input event
sourceStateEventData.Initialize(source, controller);

Debug.Assert(DetectedInputSources.Contains(source), $"{source.SourceName} was never registered with the Input Manager!");
Debug.Assert(detectedInputSources.Contains(source), $"{source.SourceName} was never registered with the Input Manager!");

DetectedInputSources.Remove(source);
detectedInputSources.Remove(source);

if (controller != null)
{
DetectedControllers.Remove(controller);
detectedControllers.Remove(controller);
}

// Pass handler through HandleEvent to perform modal/fallback logic
Expand Down Expand Up @@ -1011,7 +1015,7 @@ public void RaiseOnInputDown(IMixedRealityInputSource source, MixedRealityInputA
/// <inheritdoc />
public void RaiseOnInputDown(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, true);

Expand All @@ -1035,7 +1039,7 @@ public void RaiseOnInputPressed(IMixedRealityInputSource source, MixedRealityInp
/// <inheritdoc />
public void RaiseOnInputPressed(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, true);

Expand All @@ -1055,7 +1059,7 @@ public void RaiseOnInputPressed(IMixedRealityInputSource source, MixedRealityInp
/// <inheritdoc />
public void RaiseOnInputPressed(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction, float pressAmount)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, pressAmount);

Expand Down Expand Up @@ -1086,7 +1090,7 @@ public void RaiseOnInputUp(IMixedRealityInputSource source, MixedRealityInputAct
/// <inheritdoc />
public void RaiseOnInputUp(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, false);

Expand Down Expand Up @@ -1117,7 +1121,7 @@ public void RaisePositionInputChanged(IMixedRealityInputSource source, MixedReal
/// <inheritdoc />
public void RaisePositionInputChanged(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction, float inputPosition)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, inputPosition);

Expand All @@ -1144,7 +1148,7 @@ public void RaisePositionInputChanged(IMixedRealityInputSource source, MixedReal
/// <inheritdoc />
public void RaisePositionInputChanged(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction, Vector2 inputPosition)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, inputPosition);

Expand All @@ -1171,7 +1175,7 @@ public void RaisePositionInputChanged(IMixedRealityInputSource source, MixedReal
/// <inheritdoc />
public void RaisePositionInputChanged(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction, Vector3 position)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, position);

Expand Down Expand Up @@ -1202,7 +1206,7 @@ public void RaiseRotationInputChanged(IMixedRealityInputSource source, MixedReal
/// <inheritdoc />
public void RaiseRotationInputChanged(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction, Quaternion rotation)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, rotation);

Expand Down Expand Up @@ -1233,7 +1237,7 @@ public void RaisePoseInputChanged(IMixedRealityInputSource source, MixedRealityI
/// <inheritdoc />
public void RaisePoseInputChanged(IMixedRealityInputSource source, Handedness handedness, MixedRealityInputAction inputAction, MixedRealityPose inputData)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

inputAction = ProcessRules(inputAction, inputData);

Expand All @@ -1260,7 +1264,7 @@ public void RaisePoseInputChanged(IMixedRealityInputSource source, Handedness ha
/// <inheritdoc />
public void RaiseGestureStarted(IMixedRealityController controller, MixedRealityInputAction action)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));

action = ProcessRules(action, true);
inputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action);
Expand All @@ -1277,7 +1281,7 @@ public void RaiseGestureStarted(IMixedRealityController controller, MixedReality
/// <inheritdoc />
public void RaiseGestureUpdated(IMixedRealityController controller, MixedRealityInputAction action)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, true);
inputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action);
HandleEvent(inputEventData, OnGestureUpdated);
Expand All @@ -1293,7 +1297,7 @@ public void RaiseGestureUpdated(IMixedRealityController controller, MixedReality
/// <inheritdoc />
public void RaiseGestureUpdated(IMixedRealityController controller, MixedRealityInputAction action, Vector2 inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
vector2InputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(vector2InputEventData, OnGestureVector2PositionUpdated);
Expand All @@ -1309,7 +1313,7 @@ public void RaiseGestureUpdated(IMixedRealityController controller, MixedReality
/// <inheritdoc />
public void RaiseGestureUpdated(IMixedRealityController controller, MixedRealityInputAction action, Vector3 inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
positionInputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(positionInputEventData, OnGesturePositionUpdated);
Expand All @@ -1325,7 +1329,7 @@ public void RaiseGestureUpdated(IMixedRealityController controller, MixedReality
/// <inheritdoc />
public void RaiseGestureUpdated(IMixedRealityController controller, MixedRealityInputAction action, Quaternion inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
rotationInputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(rotationInputEventData, OnGestureRotationUpdated);
Expand All @@ -1341,7 +1345,7 @@ public void RaiseGestureUpdated(IMixedRealityController controller, MixedReality
/// <inheritdoc />
public void RaiseGestureUpdated(IMixedRealityController controller, MixedRealityInputAction action, MixedRealityPose inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
poseInputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(poseInputEventData, OnGesturePoseUpdated);
Expand All @@ -1357,7 +1361,7 @@ public void RaiseGestureUpdated(IMixedRealityController controller, MixedReality
/// <inheritdoc />
public void RaiseGestureCompleted(IMixedRealityController controller, MixedRealityInputAction action)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, false);
inputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action);
HandleEvent(inputEventData, OnGestureCompleted);
Expand All @@ -1373,7 +1377,7 @@ public void RaiseGestureCompleted(IMixedRealityController controller, MixedReali
/// <inheritdoc />
public void RaiseGestureCompleted(IMixedRealityController controller, MixedRealityInputAction action, Vector2 inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
vector2InputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(vector2InputEventData, OnGestureVector2PositionCompleted);
Expand All @@ -1389,7 +1393,7 @@ public void RaiseGestureCompleted(IMixedRealityController controller, MixedReali
/// <inheritdoc />
public void RaiseGestureCompleted(IMixedRealityController controller, MixedRealityInputAction action, Vector3 inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
positionInputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(positionInputEventData, OnGesturePositionCompleted);
Expand All @@ -1405,7 +1409,7 @@ public void RaiseGestureCompleted(IMixedRealityController controller, MixedReali
/// <inheritdoc />
public void RaiseGestureCompleted(IMixedRealityController controller, MixedRealityInputAction action, Quaternion inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
rotationInputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(rotationInputEventData, OnGestureRotationCompleted);
Expand All @@ -1421,7 +1425,7 @@ public void RaiseGestureCompleted(IMixedRealityController controller, MixedReali
/// <inheritdoc />
public void RaiseGestureCompleted(IMixedRealityController controller, MixedRealityInputAction action, MixedRealityPose inputData)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, inputData);
poseInputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action, inputData);
HandleEvent(poseInputEventData, OnGesturePoseCompleted);
Expand All @@ -1437,7 +1441,7 @@ public void RaiseGestureCompleted(IMixedRealityController controller, MixedReali
/// <inheritdoc />
public void RaiseGestureCanceled(IMixedRealityController controller, MixedRealityInputAction action)
{
Debug.Assert(DetectedInputSources.Contains(controller.InputSource));
Debug.Assert(detectedInputSources.Contains(controller.InputSource));
action = ProcessRules(action, false);
inputEventData.Initialize(controller.InputSource, controller.ControllerHandedness, action);
HandleEvent(inputEventData, OnGestureCanceled);
Expand All @@ -1457,7 +1461,7 @@ public void RaiseGestureCanceled(IMixedRealityController controller, MixedRealit
/// <inheritdoc />
public void RaiseSpeechCommandRecognized(IMixedRealityInputSource source, MixedRealityInputAction inputAction, RecognitionConfidenceLevel confidence, TimeSpan phraseDuration, DateTime phraseStartTime, string text)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

// Create input event
speechEventData.Initialize(source, inputAction, confidence, phraseDuration, phraseStartTime, text);
Expand All @@ -1480,7 +1484,7 @@ public void RaiseSpeechCommandRecognized(IMixedRealityInputSource source, MixedR
/// <inheritdoc />
public void RaiseDictationHypothesis(IMixedRealityInputSource source, string dictationHypothesis, AudioClip dictationAudioClip = null)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

// Create input event
dictationEventData.Initialize(source, dictationHypothesis, dictationAudioClip);
Expand All @@ -1499,7 +1503,7 @@ public void RaiseDictationHypothesis(IMixedRealityInputSource source, string dic
/// <inheritdoc />
public void RaiseDictationResult(IMixedRealityInputSource source, string dictationResult, AudioClip dictationAudioClip = null)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

// Create input event
dictationEventData.Initialize(source, dictationResult, dictationAudioClip);
Expand All @@ -1518,7 +1522,7 @@ public void RaiseDictationResult(IMixedRealityInputSource source, string dictati
/// <inheritdoc />
public void RaiseDictationComplete(IMixedRealityInputSource source, string dictationResult, AudioClip dictationAudioClip)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

// Create input event
dictationEventData.Initialize(source, dictationResult, dictationAudioClip);
Expand All @@ -1537,7 +1541,7 @@ public void RaiseDictationComplete(IMixedRealityInputSource source, string dicta
/// <inheritdoc />
public void RaiseDictationError(IMixedRealityInputSource source, string dictationResult, AudioClip dictationAudioClip = null)
{
Debug.Assert(DetectedInputSources.Contains(source));
Debug.Assert(detectedInputSources.Contains(source));

// Create input event
dictationEventData.Initialize(source, dictationResult, dictationAudioClip);
Expand Down