Skip to content

Commit a7514ef

Browse files
committed
Add new input action focus handling
1 parent 217866f commit a7514ef

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

org.mixedrealitytoolkit.core/Subsystems/MRTKLifecycleManager.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using Unity.Profiling;
77
using UnityEngine;
8+
using UnityEngine.InputSystem;
89

910
namespace MixedReality.Toolkit.Subsystems
1011
{
@@ -18,6 +19,9 @@ public class MRTKLifecycleManager :
1819
MonoBehaviour,
1920
IDisposable
2021
{
22+
[SerializeField, Tooltip("A set of input actions to enable/disable according to the app's focus state.")]
23+
private InputActionReference[] inputActionReferences;
24+
2125
private List<IMRTKManagedSubsystem> managedSubsystems = new List<IMRTKManagedSubsystem>();
2226

2327
/// <summary>
@@ -176,6 +180,33 @@ private void LateUpdate()
176180
}
177181
}
178182

183+
/// <summary>
184+
/// Sent to all GameObjects when the player gets or loses focus.
185+
/// </summary>
186+
/// <param name="focus"><see langword="true"/> if the GameObjects have focus, else <see langword="false"/>.</param>
187+
protected void OnApplicationFocus(bool focus)
188+
{
189+
// We want to ensure we're focused for input, as some runtimes continue reporting "tracked" while pose updates are paused.
190+
// This is allowed, per-spec, as a "should": "Runtimes should make input actions inactive while the application is unfocused,
191+
// and applications should react to an inactive input action by skipping rendering of that action's input avatar
192+
// (depictions of hands or other tracked objects controlled by the user)."
193+
194+
if (focus)
195+
{
196+
foreach (InputActionReference reference in inputActionReferences)
197+
{
198+
reference.action.Enable();
199+
}
200+
}
201+
else
202+
{
203+
foreach (InputActionReference reference in inputActionReferences)
204+
{
205+
reference.action.Disable();
206+
}
207+
}
208+
}
209+
179210
#endregion MonoBehaviour
180211

181212
/// <summary>

org.mixedrealitytoolkit.input/Assets/Prefabs/MRTK XR Rig.prefab

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,9 @@ MonoBehaviour:
377377
m_Script: {fileID: 11500000, guid: 1a107350295baaf4489642caa92f05de, type: 3}
378378
m_Name:
379379
m_EditorClassIdentifier:
380+
inputActionReferences:
381+
- {fileID: -7613329581162844239, guid: 18c412191cdc9274897f101c7fd5316f, type: 3}
382+
- {fileID: 3239510804178183174, guid: 18c412191cdc9274897f101c7fd5316f, type: 3}
380383
--- !u!1 &7735890427496681069
381384
GameObject:
382385
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)