Skip to content

Commit 57c6698

Browse files
committed
Convert to using IReadOnlyBindableVariable
1 parent 03e4095 commit 57c6698

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

org.mixedrealitytoolkit.input/Controllers/HandModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ protected virtual void Start()
9494
}
9595
}
9696

97-
MRTKInputFocusManager.OnXrSessionFocus.AddListener(OnXrSessionFocus);
97+
MRTKInputFocusManager.XrSessionHasFocus.SubscribeAndUpdate(OnXrSessionFocus);
9898
}
9999

100100
/// <summary>
101101
/// See <see cref="MonoBehaviour"/>.
102102
/// </summary>
103-
private void OnDestroy() => MRTKInputFocusManager.OnXrSessionFocus.RemoveListener(OnXrSessionFocus);
103+
private void OnDestroy() => MRTKInputFocusManager.XrSessionHasFocus.Unsubscribe(OnXrSessionFocus);
104104

105105
/// <summary>
106106
/// Sent to all GameObjects when the player gets or loses focus.

org.mixedrealitytoolkit.input/Subsystems/Hands/HandsProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override bool TryGetEntireHand(XRNode handNode, out IReadOnlyList<HandJoi
6161
{
6262
Debug.Assert(handNode == XRNode.LeftHand || handNode == XRNode.RightHand, "Non-hand XRNode used in TryGetEntireHand query.");
6363

64-
if (!MRTKInputFocusManager.HasFocus)
64+
if (!MRTKInputFocusManager.XrSessionHasFocus.Value)
6565
{
6666
jointPoses = Array.Empty<HandJointPose>();
6767
return false;
@@ -75,7 +75,7 @@ public override bool TryGetJoint(TrackedHandJoint joint, XRNode handNode, out Ha
7575
{
7676
Debug.Assert(handNode == XRNode.LeftHand || handNode == XRNode.RightHand, "Non-hand XRNode used in TryGetJoint query.");
7777

78-
if (!MRTKInputFocusManager.HasFocus)
78+
if (!MRTKInputFocusManager.XrSessionHasFocus.Value)
7979
{
8080
jointPose = default;
8181
return false;

org.mixedrealitytoolkit.input/Utilities/MRTKInputFocusManager.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the BSD 3-Clause
33

44
using System.Collections.Generic;
5+
using Unity.XR.CoreUtils.Bindings.Variables;
56
using UnityEngine;
6-
using UnityEngine.Events;
77
using UnityEngine.InputSystem;
88

99
namespace 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

Comments
 (0)