@@ -60,15 +60,31 @@ public Transform ModelPrefab
6060
6161 #endregion Associated hand select values
6262
63+ /// <summary>
64+ /// See <see cref="MonoBehaviour"/>.
65+ /// </summary>
66+ protected virtual void Awake ( )
67+ {
68+ // Create empty container transform for the model if none specified.
69+ // This is not strictly necessary to create since this GameObject could be used
70+ // as the parent for the instantiated prefab, but doing so anyway for backwards compatibility.
71+ if ( modelParent == null )
72+ {
73+ modelParent = new GameObject ( $ "[{ gameObject . name } ] Model Parent") . transform ;
74+ modelParent . SetParent ( transform , false ) ;
75+ modelParent . SetLocalPositionAndRotation ( Vector3 . zero , Quaternion . identity ) ;
76+ }
77+ }
78+
6379 /// <summary>
6480 /// A Unity event function that is called on the frame when a script is enabled just before any of the update methods are called the first time.
6581 /// </summary>
6682 protected virtual void Start ( )
6783 {
6884 // Instantiate the model prefab if it is set
69- if ( ModelPrefab != null )
85+ if ( modelPrefab != null )
7086 {
71- model = Instantiate ( ModelPrefab , ModelParent ) ;
87+ model = Instantiate ( modelPrefab , modelParent ) ;
7288
7389 Debug . Assert ( selectInput != null , $ "The Select Input reader for { name } is not set and will not be used with the instantiated hand model.") ;
7490
@@ -80,20 +96,23 @@ protected virtual void Start()
8096 }
8197 }
8298
99+ #if ! UNITY_EDITOR
83100 /// <summary>
84- /// See <see cref="MonoBehaviour"/> .
101+ /// Sent to all GameObjects when the player gets or loses focus .
85102 /// </summary>
86- protected virtual void Awake ( )
103+ /// <param name="focus"><see langword="true"/> if the GameObjects have focus, else <see langword="false"/>.</param>
104+ protected void OnApplicationFocus ( bool focus )
87105 {
88- // Create empty container transform for the model if none specified.
89- // This is not strictly necessary to create since this GameObject could be used
90- // as the parent for the instantiated prefab, but doing so anyway for backwards compatibility.
91- if ( modelParent == null )
106+ // We want to ensure we're focused for input visualization, as some runtimes continue reporting "tracked" while pose updates are paused.
107+ // This is allowed, per-spec, as a "should": "Runtimes should make input actions inactive while the application is unfocused,
108+ // and applications should react to an inactive input action by skipping rendering of that action's input avatar
109+ // (depictions of hands or other tracked objects controlled by the user)."
110+
111+ if ( modelParent != null )
92112 {
93- modelParent = new GameObject ( $ "[{ gameObject . name } ] Model Parent") . transform ;
94- modelParent . SetParent ( transform , false ) ;
95- modelParent . SetLocalPositionAndRotation ( Vector3 . zero , Quaternion . identity ) ;
113+ modelParent . gameObject . SetActive ( focus ) ;
96114 }
97115 }
116+ #endif // !UNITY_EDITOR
98117 }
99118}
0 commit comments