int SwipeDirectionToIndexDelta(MLInputControllerTouchpadGestureDirection direction) { switch (direction) { case MLInputControllerTouchpadGestureDirection.Up: return(1); case MLInputControllerTouchpadGestureDirection.Down: return(-1); default: return(0); } }
//Event Handlers: private void HandleTap(MLInputControllerTouchpadGestureDirection Direction) { switch (Direction) { case MLInputControllerTouchpadGestureDirection.Up: ScrollUp(); break; case MLInputControllerTouchpadGestureDirection.Down: ScrollDown(); break; } }
void HandleSwipe(MLInputControllerTouchpadGestureDirection direction) { if (direction == MLInputControllerTouchpadGestureDirection.Up && _activeIndex > 0) { _scrollRect.verticalNormalizedPosition += 0.5f; UpdateActiveRecipe(direction); } if (direction == MLInputControllerTouchpadGestureDirection.Down && _activeIndex < _recipes.Count - 1) { _scrollRect.verticalNormalizedPosition -= 0.5f; UpdateActiveRecipe(direction); } }
void UpdateActiveTimer(MLInputControllerTouchpadGestureDirection direction) { int oldTimer = active_timer_index; if (TimeSelect && direction == MLInputControllerTouchpadGestureDirection.Right) { count += 1; active_timer_index = StepCanvas.currActive[count]; } if (TimeSelect && direction == MLInputControllerTouchpadGestureDirection.Left) { count -= 1; active_timer_index = StepCanvas.currActive[count]; } }
void UpdateActiveRecipe(MLInputControllerTouchpadGestureDirection direction) { GameObject previousCard = _cards[_activeIndex]; if (direction == MLInputControllerTouchpadGestureDirection.Up) { _activeIndex -= 1; } if (direction == MLInputControllerTouchpadGestureDirection.Down) { _activeIndex += 1; } GameObject nextCard = _cards[_activeIndex]; previousCard.GetComponent <Image>().color = _baseColor; nextCard.GetComponent <Image>().color = _highlightedColor; }
void UpdateListRecipe(MLInputControllerTouchpadGestureDirection direction) { GameObject previousStep = _buttons[_selectingRecipeIndex]; if (Selecting && direction == MLInputControllerTouchpadGestureDirection.Up) { _selectingRecipeIndex -= 1; } if (Selecting && direction == MLInputControllerTouchpadGestureDirection.Down) { _selectingRecipeIndex += 1; } GameObject nextStep = _buttons[_selectingRecipeIndex]; previousStep.GetComponent <Image>().color = _baseColor; nextStep.GetComponent <Image>().color = _selectingColor; }
private void HandleTouchPad(MLInputControllerTouchpadGestureDirection direction) { switch (direction) { case MLInputControllerTouchpadGestureDirection.Left: Left(); break; case MLInputControllerTouchpadGestureDirection.Right: Right(); break; case MLInputControllerTouchpadGestureDirection.Up: Up(); break; case MLInputControllerTouchpadGestureDirection.Down: Down(); break; } }
//Loops: private void Update() { if (_previousHand != handedness) { _previousHand = handedness; GetControl(); } //no control? if (Control == null) { return; } //control pose: Position = Control.Position; Orientation = Control.Orientation; if (followControl) { transform.position = Position; transform.rotation = Orientation; } //touch down: if (!Touch && Control.Touch1Active) { Touch = true; StartCoroutine("TouchHold"); //resets: TouchMoved = false; TouchRadialDelta = 0; //current for comparisons: Vector4 tempTouch = GetTouch1Info(); //double - must be close to last touch and quick enough: float distanceFromLastTouchDown = Vector2.Distance(tempTouch, TouchValue); float durationSinceLastTouch = Time.realtimeSinceStartup - _lastTouchTime; if (distanceFromLastTouchDown <= _maxDoubleTouchDistance && durationSinceLastTouch < _touchDoubleDuration) { OnDoubleTap?.Invoke(TouchValue); } //cache: TouchValue = tempTouch; _touchBeganValue = TouchValue; _touchBeganTime = Time.realtimeSinceStartup; _lastTouchTime = Time.realtimeSinceStartup; OnTouchDown?.Invoke(TouchValue); } //touch movement: if (Touch) { //current for comparisons: Vector4 tempTouch = GetTouch1Info(); //touch force delta tracking: if (tempTouch.z != TouchValue.z) { if (tempTouch.z > TouchValue.z) { //touch is getting stronger: if (!ForceTouch && tempTouch.z >= _forceTouchDownThreshold) { ForceTouch = true; _wasForceTouched = true; OnForceTouchDown?.Invoke(); } } else { //touch is getting weaker: if (ForceTouch && tempTouch.z <= _forceTouchUpThreshold) { ForceTouch = false; OnForceTouchUp?.Invoke(); } } } //since force touch can make values go crazy we ignore everything if it happened: if (!_wasForceTouched) { //did we have an intentional initial move? if (!TouchMoved) { //did we initially move far enough? float movedFromInitialTouchDistance = Vector2.Distance(tempTouch, _touchBeganValue); if (movedFromInitialTouchDistance > _touchBeganMovingThreshold) { TouchMoved = true; OnTouchBeganMoving?.Invoke(); } } //only track subsequent moves if we initially began moving: if (TouchMoved) { //did we have an intentional move? float movedDistance = Vector2.Distance(TouchValue, tempTouch); if (TouchValue != tempTouch && movedDistance > 0 && movedDistance > _minTouchMove) { //moved: OnTouchMove?.Invoke(TouchValue); //radial move: float angleDelta = tempTouch.w - TouchValue.w; if (OnTouchRadialMove != null) { TouchRadialDelta = angleDelta; OnTouchRadialMove?.Invoke(angleDelta); } //cache: TouchValue = tempTouch; } } } } //touch up: if (!Control.Touch1Active && Touch) { //status: Touch = false; TouchMoved = false; TouchValue = GetTouch1Info(); StopCoroutine("TouchHold"); //meta on touch sequence: Vector2 start = _touchBeganValue; Vector2 end = TouchValue; float distanceFromTouchStart = Vector2.Distance(start, end); float durationFromTouchStart = Time.realtimeSinceStartup - _touchBeganTime; //since force touch can make values go crazy we ignore everything if it happened: if (!_wasForceTouched) { //swipe determinations: if (distanceFromTouchStart >= _minSwipeDistance) { //swiped - we only calculate if the event is registered: if (OnSwipe != null) { //swipes must be quicker than _maxSwipeDuration: if (durationFromTouchStart < _maxSwipeDuration) { //get angle: Vector2 swipe = (end - start).normalized; float swipeAngle = Vector2.Angle(Vector2.up, swipe); //swiped to the left? then we need to continue to 360 degrees: if (end.x < start.x) { swipeAngle = 360 - swipeAngle; } //determine swipe direction: MLInputControllerTouchpadGestureDirection direction = MLInputControllerTouchpadGestureDirection.Left; if (swipeAngle > 315 || swipeAngle <= 45) { direction = MLInputControllerTouchpadGestureDirection.Up; } else if (swipeAngle > 45 && swipeAngle <= 135) { direction = MLInputControllerTouchpadGestureDirection.Right; } else if (swipeAngle > 135 && swipeAngle <= 225) { direction = MLInputControllerTouchpadGestureDirection.Down; } OnSwipe?.Invoke(direction); } } } else { //tapped - we only calculate if the event is registered: if (OnTapped != null) { //taps must be quicker than _maxTapDuration: if (durationFromTouchStart < _maxTapDuration) { //determine tap location: MLInputControllerTouchpadGestureDirection direction = MLInputControllerTouchpadGestureDirection.Left; if (TouchValue.w > 315 || TouchValue.w <= 45) { direction = MLInputControllerTouchpadGestureDirection.Up; } else if (TouchValue.w > 45 && TouchValue.w <= 135) { direction = MLInputControllerTouchpadGestureDirection.Right; } else if (TouchValue.w > 135 && TouchValue.w <= 225) { direction = MLInputControllerTouchpadGestureDirection.Down; } OnTapped?.Invoke(direction); } } } } //we ultimately released so fire that event: OnTouchUp?.Invoke(TouchValue); //reset force touch activity on full release only to avoid any slight swipes at the end of release: _wasForceTouched = false; //if a user releases rapidly after a force press this will catch the release: if (ForceTouch) { ForceTouch = false; OnForceTouchUp?.Invoke(); } } //trigger: if (TriggerValue != Control.TriggerValue) { //trigger began moving: if (TriggerValue == 0) { OnTriggerPressBegan?.Invoke(); } //trigger moved: OnTriggerMove?.Invoke(Control.TriggerValue - TriggerValue); //trigger released: if (Control.TriggerValue == 0) { OnTriggerPressEnded?.Invoke(); } TriggerValue = Control.TriggerValue; } }
private void HandleTapped(MLInputControllerTouchpadGestureDirection value) { AddEvent("Tap " + value); }
private void HandleSwipe(MLInputControllerTouchpadGestureDirection value) { AddEvent("Swipe " + value); }
void HandleSwipe(MLInputControllerTouchpadGestureDirection direction) { _startActivated = !_startActivated; }
private void HandleTouch() { MLInputControllerTouchpadGestureType gesture = _controllerConnectionHandler.ConnectedController.TouchpadGesture.Type; if (gesture != MLInputControllerTouchpadGestureType.Swipe) { return; } MLInputControllerTouchpadGestureDirection direction = _controllerConnectionHandler.ConnectedController.TouchpadGesture.Direction; if (_mode == touchMode.Beam) { if (direction == MLInputControllerTouchpadGestureDirection.Up) { _beamLen += _changeRate; } else if (direction == MLInputControllerTouchpadGestureDirection.Down) { _beamLen -= _changeRate; if (_beamLen < 0) { _beamLen = 0; } } } else if (_mode == touchMode.Rotation) { if (direction == MLInputControllerTouchpadGestureDirection.Right) { _modelRotation -= _changeRateRotation; } else if (direction == MLInputControllerTouchpadGestureDirection.Left) { _modelRotation += _changeRateRotation; } if (_modelRotation > 360) { _modelRotation -= 360; } else if (_modelRotation < -360) { _modelRotation += 360; } _placementObject.transform.rotation = Quaternion.Euler(0, _modelRotation, 0); } else if (_mode == touchMode.Scale) { if (direction == MLInputControllerTouchpadGestureDirection.Up) { _modelScale += _changeRate; } else if (direction == MLInputControllerTouchpadGestureDirection.Down) { _modelScale -= _changeRate; if (_modelScale < 0) { _modelScale = 0; } } _placementObject.transform.localScale = new Vector3(_modelScale, _modelScale, _modelScale); } }
void HandleSwipe(MLInputControllerTouchpadGestureDirection direction) { Image viewportImage = GameObject.Find("Viewport").GetComponent <Image>(); if (!TimeSelect) { if (!Selecting && direction == MLInputControllerTouchpadGestureDirection.Left) { viewportImage.color = _viewportActiveColor; Selecting = true; _selectingRecipeIndex = StepCanvas.step_number; PrevNormPosition = ScrollRect.verticalNormalizedPosition; } if (Selecting && direction == MLInputControllerTouchpadGestureDirection.Right) { viewportImage.color = Color.white; Selecting = false; if (_selectingRecipeIndex != StepCanvas.step_number) { ScrollRect.verticalNormalizedPosition = PrevNormPosition; } } if (Selecting && direction == MLInputControllerTouchpadGestureDirection.Up && _selectingRecipeIndex > 0) { ScrollRect.verticalNormalizedPosition += 0.2f; UpdateListRecipe(direction); } if (Selecting && direction == MLInputControllerTouchpadGestureDirection.Down && _selectingRecipeIndex < _buttons.Count - 1) { ScrollRect.verticalNormalizedPosition -= 0.2f; UpdateListRecipe(direction); } } //For Timer Below if (StepCanvas.hasTime == true && !Selecting) { if (!TimeSelect && direction == MLInputControllerTouchpadGestureDirection.Up) { TimeSelect = true; active_timer_index = StepCanvas.currActive[0]; StepCanvas.countdown[active_timer_index].color = Color.yellow; } if (TimeSelect && direction == MLInputControllerTouchpadGestureDirection.Down) { StepCanvas.countdown[active_timer_index].color = Color.yellow; TimeSelect = false; active_timer_index = -1; } if (TimeSelect && direction == MLInputControllerTouchpadGestureDirection.Right && count < (StepCanvas.currActive.Count - 1)) { UpdateActiveTimer(direction); } if (TimeSelect && direction == MLInputControllerTouchpadGestureDirection.Left && count > 0) { UpdateActiveTimer(direction); } } }
void HandleSwipe(MLInputControllerTouchpadGestureDirection direction) { Recipe1Active = !Recipe1Active; }