Skip to content

Commit 0c978eb

Browse files
committed
Fix GetPadPressVector/GetPadTouchVector always return zero value
padPressAxis/padTouchAxis ment to record the touch position when touchpad press/touch down. Also now GetPadPressVector/GetPadTouchVector return non-zero value on pad press/touch released event. This may help implementing touchpad drag or swipe behaviour easier since you can determine the drag/swipe vector on pad release event directly.
1 parent c908c52 commit 0c978eb

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ViveInput/ControllerState.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private sealed class RCtrlState : CtrlState
8787
private Action[][] listeners;
8888
private RoleValueEventListener[][] typeListeners;
8989

90+
// Should be the touch position when touchpad press/touch down
9091
private Vector2 padPressAxis;
9192
private Vector2 padTouchAxis;
9293

@@ -318,8 +319,10 @@ public override bool Update()
318319
}
319320

320321
// record pad down axis values
321-
if (padPress) { padPressAxis = padAxis; }
322-
if (padTouch) { padTouchAxis = padAxis; }
322+
var padWasPressed = EnumUtils.GetFlag(prevButtonPressed, (int)ControllerButton.Pad);
323+
if (!padWasPressed && padPress) { padPressAxis = padAxis; }
324+
var padWasTouched = EnumUtils.GetFlag(prevButtonPressed, (int)ControllerButton.PadTouch);
325+
if (!padWasTouched && padTouch) { padTouchAxis = padAxis; }
323326

324327
// record press down time and click count
325328
var timeNow = Time.unscaledTime;
@@ -485,12 +488,18 @@ public override Vector2 GetPadAxis(bool usePrevState = false)
485488

486489
public override Vector2 GetPadPressVector()
487490
{
488-
return GetPress(ControllerButton.Pad) ? (GetPadAxis() - padPressAxis) : Vector2.zero;
491+
var wasDown = EnumUtils.GetFlag(prevButtonPressed, (int)ControllerButton.Pad);
492+
if (!wasDown) { return Vector2.zero; }
493+
var isReleased = !EnumUtils.GetFlag(currButtonPressed, (int)ControllerButton.Pad);
494+
return GetPadAxis(isReleased) - padPressAxis;
489495
}
490496

491497
public override Vector2 GetPadTouchVector()
492498
{
493-
return GetPress(ControllerButton.PadTouch) ? (GetPadAxis() - padTouchAxis) : Vector2.zero;
499+
var wasDown = EnumUtils.GetFlag(prevButtonPressed, (int)ControllerButton.PadTouch);
500+
if (!wasDown) { return Vector2.zero; }
501+
var isReleased = !EnumUtils.GetFlag(currButtonPressed, (int)ControllerButton.PadTouch);
502+
return GetPadAxis(isReleased) - padTouchAxis;
494503
}
495504

496505
public override Vector2 GetScrollDelta(ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY)

0 commit comments

Comments
 (0)