Skip to content

Commit

Permalink
Merge pull request #1892 from MrDChristop/master
Browse files Browse the repository at this point in the history
Update CustomInputSource.cs
  • Loading branch information
SimonDarksideJ authored Apr 9, 2018
2 parents ccceaf9 + 79c344f commit 02dc649
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
Expand Down Expand Up @@ -56,6 +56,11 @@ public ButtonStates()
public bool RaiseEventsBasedOnVisibility;
public InteractionSourceInfo SourceKind;

//Navigation Gesture Emulation vars
Vector3 NavigatorValues = Vector3.zero; //holds the navigation gesture values [-1,1]
Vector2 railUsedCurrently = Vector2.one;
bool isNavigatorUsingRails = false;

public Vector3 ControllerPosition;
public Quaternion ControllerRotation;

Expand Down Expand Up @@ -262,6 +267,12 @@ private void Awake()
currentlyVisible = false;
visibilityChanged = false;
controllerId = (uint)Random.value;

InteractionInputSource inputSource = FindObjectOfType<InteractionInputSource>();
if (inputSource != null)
{
isNavigatorUsingRails = inputSource.UseRailsNavigation;
}
}

private void Update()
Expand Down Expand Up @@ -411,6 +422,11 @@ private void SendControllerStateEvents(float time)
{
InputManager.Instance.RaiseManipulationCompleted(this, controllerId, currentButtonStates.CumulativeDelta);
currentButtonStates.ManipulationInProgress = false;

//Navigation Gesture Emulation
InputManager.Instance.RaiseNavigationCompleted(this, controllerId, NavigatorValues);
NavigatorValues = Vector3.zero;
railUsedCurrently = Vector2.one;
}
// Clicks and holds are based on time, and both are overruled by manipulations.
else if (currentButtonStates.HoldInProgress)
Expand Down Expand Up @@ -445,6 +461,14 @@ private void SendControllerStateEvents(float time)

InputManager.Instance.RaiseManipulationStarted(this, controllerId);
currentButtonStates.ManipulationInProgress = true;

//Navigation Gesture Emulation
InputManager.Instance.RaiseNavigationStarted(this, controllerId);
NavigatorValues = Vector3.zero;
if (isNavigatorUsingRails)
{
railUsedCurrently = (currentButtonStates.CumulativeDelta.x >= manipulationStartMovementThreshold) ? new Vector2(1, 0) : new Vector2(0, 1);
}
}
// Holds are triggered by time.
else if (!currentButtonStates.HoldInProgress && (time - currentButtonStates.SelectDownStartTime >= MaxClickDuration))
Expand All @@ -456,6 +480,11 @@ private void SendControllerStateEvents(float time)
else
{
InputManager.Instance.RaiseManipulationUpdated(this, controllerId, currentButtonStates.CumulativeDelta);

//Navigation Gesture Emulation
NavigatorValues.x = Mathf.Clamp(currentButtonStates.CumulativeDelta.x*5, -1.0f, 1.0f) * railUsedCurrently.x;
NavigatorValues.y = Mathf.Clamp(currentButtonStates.CumulativeDelta.y*5, -1.0f, 1.0f) * railUsedCurrently.y;
InputManager.Instance.RaiseNavigationUpdated(this, controllerId, NavigatorValues);
}
}

Expand Down

0 comments on commit 02dc649

Please sign in to comment.