protected override void Update() { base.Update(); leftStick = FinchVR.LeftController.GetTouchAxes(); rightStick = FinchVR.RightController.GetTouchAxes(); bool rightUp = rightStick.x >= -epsSwipe && rightStick.x <= epsSwipe && rightStick.y >= (1 - epsSwipe); bool rightDown = rightStick.x >= -epsSwipe && rightStick.x <= epsSwipe && rightStick.y <= -(1 - epsSwipe); bool leftUp = leftStick.x >= -epsSwipe && leftStick.x <= epsSwipe && leftStick.y >= (1 - epsSwipe); bool leftDown = leftStick.x >= -epsSwipe && leftStick.x <= epsSwipe && leftStick.y <= -(1 - epsSwipe); currentTime += Time.deltaTime; if (rightUp || leftUp) { if ((timesCount <= 1 && currentTime >= firstIntervalChangingHeightSec) || (timesCount > 1 && currentTime >= intervalChangingHeightSec)) { StickUp.Invoke(); if (Vibration) { if (rightUp) { RightController.HapticPulse(VibrationTimeMs); } if (leftUp) { LeftController.HapticPulse(VibrationTimeMs); } } currentTime = 0; ++timesCount; } } else if (rightDown || leftDown) { if ((timesCount <= 1 && currentTime >= firstIntervalChangingHeightSec) || (timesCount > 1 && currentTime >= intervalChangingHeightSec)) { StickDown.Invoke(); if (Vibration && rightDown) { RightController.HapticPulse(VibrationTimeMs); } if (Vibration && leftDown) { LeftController.HapticPulse(VibrationTimeMs); } currentTime = 0; ++timesCount; } } if (!(rightUp || leftUp) && !(rightDown || leftDown)) { timesCount = 0; } }
protected override void Update() { base.Update(); if (ButtonEventType == FinchButtonEventType.Right || ButtonEventType == FinchButtonEventType.Any) { detectPress(FinchChirality.Right); } if (ButtonEventType == FinchButtonEventType.Left || ButtonEventType == FinchButtonEventType.Any) { detectPress(FinchChirality.Left); } bool wasInvoked = false; if (ButtonEventType == FinchButtonEventType.BothAtOneTime) { if ((RightController.GetPress(button) && LeftController.GetPressDown(button)) || (LeftController.GetPress(button) && RightController.GetPressDown(button))) { if (FinchDownEvent != null) { FinchDownEvent.Invoke(); wasInvoked = true; } else if (FinchUpEvent != null) { FinchUpEvent.Invoke(); wasInvoked = true; } if (wasInvoked && Vibration) { RightController.HapticPulse(VibrationTimeMs); LeftController.HapticPulse(VibrationTimeMs); } } } }
protected override void Update() { ButtonEventType = FinchButtonEventType.Any; base.Update(); bool startedTouching = !bothTouching && ((LeftController.GetPress(Button) && RightController.GetPressDown(Button)) || (RightController.GetPress(Button) && LeftController.GetPressDown(Button))); bool eventCanBeInvoked = !alreadyInvoked && bothTouching; bool stoppedTouching = bothTouching && (LeftController.GetPressUp(Button) || RightController.GetPressUp(Button)); if (startedTouching) { bothTouching = true; stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); } else if (eventCanBeInvoked) { if (stopWatch.ElapsedMilliseconds >= longTapTimeMs) { stopWatch.Stop(); alreadyInvoked = true; LongTapBothTouchpads.Invoke(); if (Vibration) { RightController.HapticPulse(VibrationTimeMs); LeftController.HapticPulse(VibrationTimeMs); } } } else if (stoppedTouching) { bothTouching = false; alreadyInvoked = false; stopWatch.Stop(); } }
private void calculate(FinchChirality chirality) { Vector2 axis; float currentTime; if (chirality == FinchChirality.Right) { axis = FinchVR.RightController.GetTouchAxes(); currentTimeRight += Time.deltaTime; currentTime = currentTimeRight; } else if (chirality == FinchChirality.Left) { axis = FinchVR.LeftController.GetTouchAxes(); currentTimeLeft += Time.deltaTime; currentTime = currentTimeLeft; } else { return; } //zero bool zero = axis.x <= epsZero && axis.x >= -epsZero && axis.y <= epsZero && axis.y >= -epsZero; //stick swipe to right-left bool swipeToRight = axis.x >= (1 - epsSwipe) && axis.y >= -epsSwipe && axis.y <= epsSwipe; bool swipeToLeft = axis.x <= -(1 - epsSwipe) && axis.y >= -epsSwipe && axis.y <= epsSwipe; //stick swipe to up-down bool swipeToUp = axis.x >= -epsSwipe && axis.x <= epsSwipe && axis.y >= (1 - epsSwipe); bool swipeToDown = axis.x >= -epsSwipe && axis.x <= epsSwipe && axis.y <= -(1 - epsSwipe); bool previousWasZero = chirality == FinchChirality.Right ? previousWasZeroRight : previousWasZeroLeft; if (zero) { if (chirality == FinchChirality.Right) { currentTimeRight = 0; previousWasZeroRight = true; } else { currentTimeLeft = 0; previousWasZeroLeft = true; } return; } if (currentTime >= timeToSwapSec) { currentTime = 0; if (chirality == FinchChirality.Right) { currentTimeRight = 0; previousWasZeroRight = previousWasZero = false; } else { currentTimeLeft = 0; previousWasZeroLeft = previousWasZero = false; } } if (previousWasZero) { bool invoked = false; if (swipeToRight) { SwipeRight.Invoke(); invoked = true; } if (swipeToLeft) { SwipeLeft.Invoke(); invoked = true; } if (swipeToUp) { SwipeUp.Invoke(); invoked = true; } if (swipeToDown) { SwipeDown.Invoke(); invoked = true; } if (invoked) { if (chirality == FinchChirality.Right) { previousWasZeroRight = false; currentTimeRight = 0; if (Vibration) { RightController.HapticPulse(VibrationTimeMs); } } else { previousWasZeroLeft = false; currentTimeLeft = 0; if (Vibration) { LeftController.HapticPulse(VibrationTimeMs); } } } } }