private void CheckSwipe() { float duration = (float)fingerUpTime.Subtract(fingerDownTime).TotalSeconds; if (duration > timeThreshold) { return; } float deltaX = fingerDown.x - fingerUp.x; float deltaY = fingerDown.y - fingerUp.y; if (Mathf.Abs(deltaX) < swipeThreshold && Mathf.Abs(deltaY) < swipeThreshold) { return; } if (MenuHandler.isTipsEnable) { hideGameTip?.Invoke(); MenuHandler.isTipsEnable = false; } if (Mathf.Abs(deltaX) > Mathf.Abs(deltaY)) { if (Mathf.Abs(deltaX) >= swipeThreshold) { if (deltaX >= 0) { OnSwipeEnd?.Invoke(Vector2.up); } //snake.DirectionInput(Vector2.up); else { OnSwipeEnd?.Invoke(Vector2.down); } //snake.DirectionInput(Vector2.down); } } else if (Mathf.Abs(deltaY) >= swipeThreshold) { if (deltaY >= 0) { OnSwipeEnd?.Invoke(Vector2.left); } //snake.DirectionInput(Vector2.left); else { OnSwipeEnd?.Invoke(Vector2.right); } //snake.DirectionInput(Vector2.right); } fingerUp = fingerDown; }
public int CheckPosition() { if (graphic.position.x < -0.5f) { if (!positiveAnsw.activeSelf) { OnSwipeLeft?.Invoke(GetCardData.positiveEffects); positiveAnsw.SetActive(true); } return(-1); } else if (graphic.position.x > 0.5f) { if (!negativeAnsw.activeSelf) { OnSwipeRight?.Invoke(GetCardData.negativeEffects); negativeAnsw.SetActive(true); } return(1); } if (positiveAnsw.activeSelf) { OnSwipeEnd?.Invoke(); positiveAnsw.SetActive(false); } if (negativeAnsw.activeSelf) { OnSwipeEnd?.Invoke(); negativeAnsw.SetActive(false); } return(0); }
private void UpdateTouches() { if (input == null || input.TouchCount() == 0) { return; } if (input.TouchCount() == 1) { TouchInfo touchInfo = input.GetTouch(0); if (currentTouch.GestureType == GestureType.None) { actionStartTime = Time.realtimeSinceStartup; } touchInfo.StartTime = actionStartTime; if (touchInfo.Phase == TouchPhase.Began) { Touch touch = new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, SwipeDirection = SwipeDirection.None, SwipeLength = 0, SwipeVector = Vector2.zero }; currentTouch = touch; OnTouchStart?.Invoke(touch); } if (touchInfo.Phase == TouchPhase.Moved) { OnTouch?.Invoke(new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, }); if (touchInfo.PositionDelta.magnitude >= settings.GetSwipeLengthInPixels()) { Touch touch = new Touch { TouchInfo = touchInfo, GestureType = GestureType.Swipe, SwipeDirection = GetSwipeDirection(touchInfo.Position - touchInfo.PositionDelta, touchInfo.Position), SwipeLength = touchInfo.PositionDelta.magnitude, SwipeVector = touchInfo.PositionDelta }; switch (currentTouch.GestureType) { case GestureType.None: OnSwipeStart?.Invoke(touch); break; case GestureType.Swipe: OnSwipe?.Invoke(touch); break; } currentTouch = touch; return; } } if (touchInfo.Phase == TouchPhase.Stationary) { OnTouch?.Invoke(new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, }); touchInfo.ActionTime = Time.realtimeSinceStartup - touchInfo.StartTime; currentTouch = new Touch { TouchInfo = touchInfo, GestureType = GestureType.Tap, SwipeDirection = SwipeDirection.None, SwipeLength = 0, SwipeVector = Vector2.zero }; } if (touchInfo.Phase == TouchPhase.Ended) { OnTouchEnd?.Invoke(new Touch { TouchInfo = touchInfo, GestureType = GestureType.None, }); switch (currentTouch.GestureType) { case GestureType.Swipe: OnSwipeEnd?.Invoke(currentTouch); break; case GestureType.Tap when currentTouch.TouchInfo.ActionTime <= settings.TapTime: OnTap?.Invoke(currentTouch); break; } } } if (input.TouchCount() == 2) { TouchInfo touch0 = input.GetTouch(0); TouchInfo touch1 = input.GetTouch(1); if (currentTouch.GestureType == GestureType.None) { actionStartTime = Time.realtimeSinceStartup; } touch0.StartTime = actionStartTime; if (touch0.Phase == TouchPhase.Began || touch1.Phase == TouchPhase.Began) { Pinch pinch = new Pinch { TouchInfos = new [] { touch0, touch1 }, GestureType = GestureType.None, PinchVector = touch0.Position - touch1.Position }; currentPinch = pinch; OnPinchStart?.Invoke(currentPinch); } if (touch0.Phase != TouchPhase.Stationary || touch0.Phase == TouchPhase.Moved || touch1.Phase != TouchPhase.Stationary || touch1.Phase == TouchPhase.Moved) { Pinch pinch = new Pinch { TouchInfos = new [] { touch0, touch1 }, GestureType = GestureType.Pinch, PinchVector = touch0.Position - touch1.Position }; currentPinch = pinch; OnPinch?.Invoke(currentPinch); } if (touch0.Phase == TouchPhase.Ended || touch1.Phase == TouchPhase.Ended) { Pinch pinch = new Pinch { TouchInfos = new [] { touch0, touch1 }, GestureType = GestureType.Pinch, PinchVector = touch0.Position - touch1.Position }; currentPinch = pinch; OnPinchEnd?.Invoke(currentPinch); } } }
public void SwipeEnd(Swipe swipe) => OnSwipeEnd?.Invoke(swipe);