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

Commit

Permalink
Added a way to subscribe to input events from a poco class (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson authored Oct 2, 2019
1 parent e6bbc42 commit b6fe2b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using XRTK.Definitions.Devices;
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.Utilities;
using XRTK.EventDatum.Input;
using XRTK.Interfaces.Providers.Controllers;
using XRTK.Interfaces.Events;

Expand Down Expand Up @@ -122,6 +123,15 @@ public interface IMixedRealityInputSystem : IMixedRealityEventSystem

#region Input Events

/// <summary>
/// Raised when an input event is triggered.
/// </summary>
/// <remarks>
/// WARNING: This event should not be subscribed to by MonoBehaviours!
/// Use the InputHandler interfaces instead.
/// </remarks>
event Action<BaseInputEventData> OnInputEvent;

#region Input Source Events

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ public override void HandleEvent<T>(BaseEventData eventData, ExecuteEvents.Event
return;
}

// Sent the event to any POCO classes that have subscribed for events.
// WARNING: This event should not be subscribed to by MonoBehaviours!
// Use the InputHandler interfaces instead.
OnInputEvent?.Invoke(baseInputEventData);

// Send the event to global listeners
base.HandleEvent(eventData, eventHandler);

Expand Down Expand Up @@ -476,7 +481,7 @@ public void ClearFallbackInputStack()
/// <inheritdoc />
public bool TryGetController(IMixedRealityInputSource inputSource, out IMixedRealityController controller)
{
foreach (IMixedRealityController mixedRealityController in DetectedControllers)
foreach (var mixedRealityController in DetectedControllers)
{
if (inputSource.SourceId == mixedRealityController.InputSource.SourceId)
{
Expand All @@ -493,6 +498,9 @@ public bool TryGetController(IMixedRealityInputSource inputSource, out IMixedRea

#region Input Events

/// <inheritdoc />
public event Action<BaseInputEventData> OnInputEvent;

#region Input Source Events

/// <inheritdoc />
Expand Down

0 comments on commit b6fe2b6

Please sign in to comment.