1
- // Copyright (c) Microsoft Corporation. All rights reserved.
1
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License. See LICENSE in the project root for license information.
3
3
4
4
using System ;
@@ -56,6 +56,11 @@ public ButtonStates()
56
56
public bool RaiseEventsBasedOnVisibility ;
57
57
public InteractionSourceInfo SourceKind ;
58
58
59
+ //Navigation Gesture Emulation vars
60
+ Vector3 NavigatorValues = Vector3 . zero ; //holds the navigation gesture values [-1,1]
61
+ Vector2 railUsedCurrently = Vector2 . one ;
62
+ bool isNavigatorUsingRails = false ;
63
+
59
64
public Vector3 ControllerPosition ;
60
65
public Quaternion ControllerRotation ;
61
66
@@ -262,6 +267,12 @@ private void Awake()
262
267
currentlyVisible = false ;
263
268
visibilityChanged = false ;
264
269
controllerId = ( uint ) Random . value ;
270
+
271
+ InteractionInputSource inputSource = FindObjectOfType < InteractionInputSource > ( ) ;
272
+ if ( inputSource != null )
273
+ {
274
+ isNavigatorUsingRails = inputSource . UseRailsNavigation ;
275
+ }
265
276
}
266
277
267
278
private void Update ( )
@@ -411,6 +422,11 @@ private void SendControllerStateEvents(float time)
411
422
{
412
423
InputManager . Instance . RaiseManipulationCompleted ( this , controllerId , currentButtonStates . CumulativeDelta ) ;
413
424
currentButtonStates . ManipulationInProgress = false ;
425
+
426
+ //Navigation Gesture Emulation
427
+ InputManager . Instance . RaiseNavigationCompleted ( this , controllerId , NavigatorValues ) ;
428
+ NavigatorValues = Vector3 . zero ;
429
+ railUsedCurrently = Vector2 . one ;
414
430
}
415
431
// Clicks and holds are based on time, and both are overruled by manipulations.
416
432
else if ( currentButtonStates . HoldInProgress )
@@ -445,6 +461,14 @@ private void SendControllerStateEvents(float time)
445
461
446
462
InputManager . Instance . RaiseManipulationStarted ( this , controllerId ) ;
447
463
currentButtonStates . ManipulationInProgress = true ;
464
+
465
+ //Navigation Gesture Emulation
466
+ InputManager . Instance . RaiseNavigationStarted ( this , controllerId ) ;
467
+ NavigatorValues = Vector3 . zero ;
468
+ if ( isNavigatorUsingRails )
469
+ {
470
+ railUsedCurrently = ( currentButtonStates . CumulativeDelta . x >= manipulationStartMovementThreshold ) ? new Vector2 ( 1 , 0 ) : new Vector2 ( 0 , 1 ) ;
471
+ }
448
472
}
449
473
// Holds are triggered by time.
450
474
else if ( ! currentButtonStates . HoldInProgress && ( time - currentButtonStates . SelectDownStartTime >= MaxClickDuration ) )
@@ -456,6 +480,11 @@ private void SendControllerStateEvents(float time)
456
480
else
457
481
{
458
482
InputManager . Instance . RaiseManipulationUpdated ( this , controllerId , currentButtonStates . CumulativeDelta ) ;
483
+
484
+ //Navigation Gesture Emulation
485
+ NavigatorValues . x = Mathf . Clamp ( currentButtonStates . CumulativeDelta . x * 5 , - 1.0f , 1.0f ) * railUsedCurrently . x ;
486
+ NavigatorValues . y = Mathf . Clamp ( currentButtonStates . CumulativeDelta . y * 5 , - 1.0f , 1.0f ) * railUsedCurrently . y ;
487
+ InputManager . Instance . RaiseNavigationUpdated ( this , controllerId , NavigatorValues ) ;
459
488
}
460
489
}
461
490
0 commit comments