22// Licensed under the BSD 3-Clause
33
44using System . Collections . Generic ;
5+ using Unity . XR . CoreUtils . Bindings . Variables ;
56using UnityEngine ;
6- using UnityEngine . Events ;
77using UnityEngine . InputSystem ;
88
99namespace MixedReality . Toolkit . Input
@@ -17,20 +17,11 @@ public sealed class MRTKInputFocusManager : MonoBehaviour
1717 private InputActionReference [ ] inputActionReferences ;
1818
1919 /// <summary>
20- /// Provides an event based on the current XrSession becoming focused or not.
21- /// </summary>
22- public static UnityEvent < bool > OnXrSessionFocus { get ; } = new UnityEvent < bool > ( ) ;
23-
24- /// <summary>
25- /// Whether the current XrSession has focus or not.
20+ /// Whether the current XrSession has focus or not, stored as a bindable variable that can be subscribed to for value changes.
2621 /// </summary>
2722 /// <remarks>Always <see langword="true"/> in the editor.</remarks>
28- public static bool HasFocus => Application . isEditor ||
29- #if SNAPDRAGON_SPACES_PRESENT
30- lastSessionState == 5 ;
31- #else
32- Application . isFocused ;
33- #endif
23+ public static IReadOnlyBindableVariable < bool > XrSessionHasFocus => xrSessionHasFocus ;
24+ private static readonly BindableVariable < bool > xrSessionHasFocus = new ( Application . isEditor ) ;
3425
3526 /// <summary>
3627 /// We want to ensure we're focused for input, as some runtimes continue reporting "tracked" while pose updates are paused.
@@ -40,7 +31,7 @@ public sealed class MRTKInputFocusManager : MonoBehaviour
4031 /// </summary>
4132 private void OnFocusChange ( bool focus )
4233 {
43- OnXrSessionFocus ? . Invoke ( focus ) ;
34+ xrSessionHasFocus . Value = focus ;
4435
4536 foreach ( InputActionReference reference in inputActionReferences )
4637 {
0 commit comments