@@ -169,7 +169,8 @@ public UpdateType updateType
169
169
bool m_RotationBound ;
170
170
bool m_PositionBound ;
171
171
bool m_TrackingStateBound ;
172
- private bool visualActionsInit ;
172
+ private bool visualActionsBound ;
173
+ private bool visualActionsUpdated ;
173
174
bool m_IsFirstUpdate = true ;
174
175
175
176
private Transform xrControllerOldModel ;
@@ -180,14 +181,15 @@ void BindActions()
180
181
BindPosition ( ) ;
181
182
BindRotation ( ) ;
182
183
BindTrackingState ( ) ;
183
- InitVisualActions ( ) ;
184
+ BindVisualActions ( ) ;
184
185
}
185
186
186
187
void UnbindActions ( )
187
188
{
188
189
UnbindPosition ( ) ;
189
190
UnbindRotation ( ) ;
190
191
UnbindTrackingState ( ) ;
192
+ UnbindVisualActions ( ) ;
191
193
}
192
194
193
195
void BindPosition ( )
@@ -232,9 +234,9 @@ void BindTrackingState()
232
234
m_TrackingStateBound = true ;
233
235
}
234
236
235
- void InitVisualActions ( )
237
+ void BindVisualActions ( )
236
238
{
237
- if ( visualActionsInit )
239
+ if ( visualActionsBound )
238
240
return ;
239
241
240
242
buttonActions = new InputAction [ 6 ] ;
@@ -248,7 +250,18 @@ void InitVisualActions()
248
250
axisActions [ 0 ] = touchpadActionProperty . action ;
249
251
axisActions [ 1 ] = thumbstickActionProperty . action ;
250
252
251
- visualActionsInit = true ;
253
+ for ( int i = 0 ; i < buttonActions . Length ; i ++ )
254
+ {
255
+ buttonActions [ i ] . performed += OnVisualActionsPerformed ;
256
+ buttonActions [ i ] . canceled += OnVisualActionsCanceled ;
257
+ }
258
+ for ( int i = 0 ; i < axisActions . Length ; i ++ )
259
+ {
260
+ axisActions [ i ] . performed += OnVisualActionsPerformed ;
261
+ axisActions [ i ] . canceled += OnVisualActionsCanceled ;
262
+ }
263
+
264
+ visualActionsBound = true ;
252
265
}
253
266
254
267
void UnbindPosition ( )
@@ -290,6 +303,25 @@ void UnbindTrackingState()
290
303
m_TrackingStateBound = false ;
291
304
}
292
305
306
+ void UnbindVisualActions ( )
307
+ {
308
+ if ( ! visualActionsBound )
309
+ return ;
310
+
311
+ for ( int i = 0 ; i < buttonActions . Length ; i ++ )
312
+ {
313
+ buttonActions [ i ] . performed -= OnVisualActionsPerformed ;
314
+ buttonActions [ i ] . canceled -= OnVisualActionsCanceled ;
315
+ }
316
+ for ( int i = 0 ; i < axisActions . Length ; i ++ )
317
+ {
318
+ axisActions [ i ] . performed -= OnVisualActionsPerformed ;
319
+ axisActions [ i ] . canceled -= OnVisualActionsCanceled ;
320
+ }
321
+
322
+ visualActionsBound = false ;
323
+ }
324
+
293
325
void OnPositionPerformed ( InputAction . CallbackContext context )
294
326
{
295
327
m_CurrentPosition = context . ReadValue < Vector3 > ( ) ;
@@ -328,6 +360,16 @@ void OnTrackingStateCanceled(InputAction.CallbackContext context)
328
360
}
329
361
}
330
362
363
+ void OnVisualActionsPerformed ( InputAction . CallbackContext context )
364
+ {
365
+ visualActionsUpdated = true ;
366
+ }
367
+
368
+ void OnVisualActionsCanceled ( InputAction . CallbackContext context )
369
+ {
370
+ visualActionsUpdated = true ;
371
+ }
372
+
331
373
private void Awake ( )
332
374
{
333
375
inputProfileLoader = rigOrigin . GetComponent < InputProfileLoader > ( ) ;
@@ -472,7 +514,7 @@ protected virtual void OnBeforeRender()
472
514
protected virtual void PerformUpdate ( )
473
515
{
474
516
SetLocalTransform ( m_CurrentPosition , m_CurrentRotation ) ;
475
- if ( loadedModel && m_CurrentTrackingState != TrackingStates . None )
517
+ if ( loadedModel && visualActionsUpdated )
476
518
{
477
519
UpdateModelInput ( ) ;
478
520
}
@@ -513,6 +555,11 @@ protected virtual void SetLocalTransform(Vector3 newPosition, Quaternion newRota
513
555
514
556
private void UpdateModelInput ( )
515
557
{
558
+ if ( m_CurrentTrackingState == TrackingStates . None )
559
+ {
560
+ return ;
561
+ }
562
+ visualActionsUpdated = false ;
516
563
for ( int i = 0 ; i < 6 ; i ++ )
517
564
{
518
565
inputProfileModel . SetButtonValue ( i , buttonActions [ i ] . ReadValue < float > ( ) ) ;
0 commit comments