Skip to content

Commit 02dc649

Browse files
Merge pull request #1892 from MrDChristop/master
Update CustomInputSource.cs
2 parents ccceaf9 + 79c344f commit 02dc649

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Assets/HoloToolkit/Input/Scripts/InputSources/CustomInputSource.cs

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
using System;
@@ -56,6 +56,11 @@ public ButtonStates()
5656
public bool RaiseEventsBasedOnVisibility;
5757
public InteractionSourceInfo SourceKind;
5858

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+
5964
public Vector3 ControllerPosition;
6065
public Quaternion ControllerRotation;
6166

@@ -262,6 +267,12 @@ private void Awake()
262267
currentlyVisible = false;
263268
visibilityChanged = false;
264269
controllerId = (uint)Random.value;
270+
271+
InteractionInputSource inputSource = FindObjectOfType<InteractionInputSource>();
272+
if (inputSource != null)
273+
{
274+
isNavigatorUsingRails = inputSource.UseRailsNavigation;
275+
}
265276
}
266277

267278
private void Update()
@@ -411,6 +422,11 @@ private void SendControllerStateEvents(float time)
411422
{
412423
InputManager.Instance.RaiseManipulationCompleted(this, controllerId, currentButtonStates.CumulativeDelta);
413424
currentButtonStates.ManipulationInProgress = false;
425+
426+
//Navigation Gesture Emulation
427+
InputManager.Instance.RaiseNavigationCompleted(this, controllerId, NavigatorValues);
428+
NavigatorValues = Vector3.zero;
429+
railUsedCurrently = Vector2.one;
414430
}
415431
// Clicks and holds are based on time, and both are overruled by manipulations.
416432
else if (currentButtonStates.HoldInProgress)
@@ -445,6 +461,14 @@ private void SendControllerStateEvents(float time)
445461

446462
InputManager.Instance.RaiseManipulationStarted(this, controllerId);
447463
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+
}
448472
}
449473
// Holds are triggered by time.
450474
else if (!currentButtonStates.HoldInProgress && (time - currentButtonStates.SelectDownStartTime >= MaxClickDuration))
@@ -456,6 +480,11 @@ private void SendControllerStateEvents(float time)
456480
else
457481
{
458482
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);
459488
}
460489
}
461490

0 commit comments

Comments
 (0)