11// Copyright (c) Mixed Reality Toolkit Contributors
22// Licensed under the BSD 3-Clause
33
4+ using System . Collections . Generic ;
45using UnityEngine ;
56using UnityEngine . Events ;
67using UnityEngine . InputSystem ;
@@ -20,6 +21,18 @@ public sealed class MRTKInputFocusManager : MonoBehaviour
2021 /// </summary>
2122 public static UnityEvent < bool > OnXrSessionFocus { get ; } = new UnityEvent < bool > ( ) ;
2223
24+ /// <summary>
25+ /// Whether the current XrSession has focus or not.
26+ /// </summary>
27+ public static bool HasFocus =>
28+ #if UNITY_EDITOR
29+ true ;
30+ #elif SNAPDRAGON_SPACES_PRESENT
31+ lastSessionState == 5 ;
32+ #else
33+ Application . isFocused ;
34+ #endif
35+
2336 /// <summary>
2437 /// We want to ensure we're focused for input, as some runtimes continue reporting "tracked" while pose updates are paused.
2538 /// This is allowed, per-spec, as a "should": "Runtimes should make input actions inactive while the application is unfocused,
@@ -43,15 +56,25 @@ private void OnFocusChange(bool focus)
4356 }
4457 }
4558
46- #if USING_SNAPDRAGON_SPACES_SDK
59+ #if SNAPDRAGON_SPACES_PRESENT
60+ private static readonly List < Qualcomm . Snapdragon . Spaces . SpacesOpenXRFeature > featureList = new ( ) ;
61+ private static int lastSessionState = - 1 ;
4762 private Qualcomm . Snapdragon . Spaces . SpacesOpenXRFeature spacesOpenXRFeature = null ;
48- private int lastSessionState = - 1 ;
4963
5064 private void Update ( )
5165 {
5266 if ( spacesOpenXRFeature == null )
5367 {
54- spacesOpenXRFeature = UnityEngine . XR . OpenXR . OpenXRSettings . Instance . GetFeature < Qualcomm . Snapdragon . Spaces . SpacesOpenXRFeature > ( ) ;
68+ int count = UnityEngine . XR . OpenXR . OpenXRSettings . Instance . GetFeatures ( featureList ) ;
69+ for ( int i = 0 ; i < count ; i ++ )
70+ {
71+ Qualcomm . Snapdragon . Spaces . SpacesOpenXRFeature feature = featureList [ i ] ;
72+ if ( feature != null && feature . enabled )
73+ {
74+ spacesOpenXRFeature = feature ;
75+ break ;
76+ }
77+ }
5578 }
5679
5780 // XrSessionState maps better to this behavior than OnApplicationFocus but isn't
0 commit comments