private void HandleSwipe(PointerEventData pointerEventData) { Vector3 localPressPosition = this.GetLocalPosition(pointerEventData.pressPosition); Vector3 localPosition = this.GetLocalPosition(pointerEventData.position); float direction = localPosition.x - localPressPosition.x; onSwipe?.Invoke(direction); }
void JudgeInputIsRight() { if (timeBegin > 0 && timeEnd > 0) { float timeDelta = timeEnd - timeBegin; Vector2 touchDelta = touchEnd - touchBegin; Vector2 direction = GetDirection(ref touchDelta); if (direction != Vector2.zero) { if (directionFirst == Vector2.zero) { directionFirst = direction; } var swipeInfo = new SwipeInfo { touchBegin = touchBegin, direction = direction, directionFirst = directionFirst, touchDelta = touchDelta, timeDelta = timeDelta, hasFreePass = false, }; if (isCancelable && directionFirst != direction) { onSwipeCancel.Invoke(); Reset(); } else if (Math.Max(Math.Abs(touchDelta.x), Math.Abs(touchDelta.y)) > threshold) { onSwipeEnd.Invoke(swipeInfo); Reset(); } else if (isTouchDown) { onSwipeMove.Invoke(swipeInfo); } else { onSwipeEnd.Invoke(swipeInfo); Reset(); } } } }
protected virtual void Swipe() { MMSwipeEvent swipeEvent = new MMSwipeEvent(_swipeDirection, _angle, _length, _firstTouchPosition, _destination); MMEventManager.TriggerEvent(swipeEvent); if (ZoneSwiped != null) { ZoneSwiped.Invoke(swipeEvent); } }
void Update() { if (isSwiping) { if (Input.GetMouseButtonUp(0)) { swipeDelta = Input.mousePosition - swipeStartPosition; if (Mathf.Abs(swipeDelta.x) > Mathf.Abs(swipeDelta.y)) { if (swipeDelta.x > 0f) { swipeEvent.Invoke("right"); } else { swipeEvent.Invoke("left"); } } else { if (swipeDelta.y > 0f) { swipeEvent.Invoke("up"); } else { swipeEvent.Invoke("down"); } } isSwiping = false; } } else { if (Input.GetMouseButtonDown(0)) { swipeStartPosition = Input.mousePosition; isSwiping = true; } } }
void SendSwipe(SwipeDirection direction) { SwipeData swipeData = new SwipeData() { Direction = direction, StartPos = fingerDownPosition, EndPos = fingerUpPosition }; OnSwipe.Invoke(swipeData); }
private void SwipeInput() { if (GetTouchInput() || GetMouseInput()) { // Swipe already ended, don't detect until a new swipe has begun if (swipeEnded) { return; } Vector2 currentSwipe = secondPressPos - firstPressPos; float swipeCm = currentSwipe.magnitude / dpcm; // Check the swipe is long enough to count as a swipe (not a touch, etc) if (swipeCm < minSwipeLength) { // Swipe was not long enough, abort if (!triggerSwipeAtMinLength) { if (Application.isEditor) { //Debug.Log("[SwipeManager] Swipe was not long enough."); OnSwipeFail.Invoke(); } swipeDirection = Swipe.None; } return; } swipeEndTime = Time.time; swipeVelocity = currentSwipe * (swipeEndTime - swipeStartTime); swipeDirection = GetSwipeDirByTouch(currentSwipe); swipeEnded = true; if (Mathf.Abs(swipeStartTime - swipeEndTime) < 1.3f) { OnSwipeDetected.Invoke(swipeDirection, swipeVelocity.normalized); } else { OnSwipeFail.Invoke(); } //Debug.Log("Swipe Detected " + swipeDirection + " " + swipeVelocity + " " + currentSwipe); } else { swipeDirection = Swipe.None; } }
void ReadTouchInput(bool isPointerOverGui) { if (Input.touchCount > 0 && !isPointerOverGui) { var firstTouch = Input.GetTouch(0); var touchPhase = firstTouch.phase; var touchPosition = firstTouch.position; if (touchPhase == TouchPhase.Began) { timeBegin = Time.time; touchBegin = touchPosition; isTouchDown = true; onSwipeStart.Invoke(new SwipeInfo { touchBegin = touchBegin }); } if (touchBegin != Vector2.zero) { timeEnd = Time.time; touchEnd = touchPosition; } if (touchPhase == TouchPhase.Ended) { isTouchDown = false; } if (touchPhase == TouchPhase.Canceled) { onSwipeCancel.Invoke(); Reset(); } } }
public void OnEndDrag(PointerEventData eventData) { Vector3 drag = (eventData.position - eventData.pressPosition).normalized; Direction direction; if (Mathf.Abs(drag.x) > Mathf.Abs(drag.y)) { direction = (drag.x > 0) ? Direction.Right : Direction.Left; } else { direction = (drag.y > 0) ? Direction.Up : Direction.Down; } Debug.Log("Dragged: " + direction); SwipeEvent.Invoke(direction); }
/// <summary> /// スワイプ検出 /// </summary> private void DetectSwipe() { if (Input.GetMouseButtonDown(0)) { SwipeProc(); from = to; } else if (Input.GetMouseButtonUp(0)) { if (isSwiping) { isSwiping = false; SwipeProc(); onEndedSwipe.Invoke(new SwipeEventData(this, delta, deltaMag)); } } else if (Input.GetMouseButton(0)) { SwipeProc(); if (isDebug) { Debug.Log(deltaMag); } if (deltaMag > detectDistance) { if (!isSwiping) { isSwiping = true; SwipeProc(); onStartedSwipe.Invoke(new SwipeEventData(this, delta, deltaMag)); } else { SwipeProc(); onSwiping.Invoke(new SwipeEventData(this, delta, deltaMag)); } } } }
private void OnSwipe() { SwipeEvent?.Invoke(_touchMovement); }
/// <summary> /// Gets the inputs /// </summary> private void Update() { bool tap = false; #region Standalone Inputs if (Input.GetMouseButtonDown(0)) { tap = true; startTouch = Input.mousePosition; } else if (Input.GetMouseButtonUp(0)) { startTouch = swipeDelta = Vector2.zero; return; } if (Input.GetKeyUp(KeyCode.LeftArrow)) { SwipeEvent?.Invoke(Enums.Direction.Left); } else if (Input.GetKeyUp(KeyCode.RightArrow)) { SwipeEvent?.Invoke(Enums.Direction.Right); return; } else if (Input.GetKeyUp(KeyCode.UpArrow)) { SwipeEvent?.Invoke(Enums.Direction.Up); return; } else if (Input.GetKeyUp(KeyCode.DownArrow)) { SwipeEvent?.Invoke(Enums.Direction.Down); return; } else { if (tap) { TapEvent?.Invoke(); } } #endregion #region Mobile Inputs tap = false; if (Input.touches.Length != 0) { if (Input.touches[0].phase == TouchPhase.Began) { tap = true; startTouch = Input.mousePosition; } else if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled) { startTouch = swipeDelta = Vector2.zero; } } #endregion //Calculate distance swipeDelta = Vector2.zero; if (startTouch != Vector2.zero) { //Check with mobile if (Input.touches.Length != 0) { swipeDelta = Input.touches[0].position - startTouch; } //Check with standalone else if (Input.GetMouseButton(0)) { swipeDelta = (Vector2)(Input.mousePosition) - startTouch; } } //Check if we're beyong the deadzone if (swipeDelta.magnitude > DEADZONE) { //This is a confirmed swipe float x = swipeDelta.x; float y = swipeDelta.y; if (Mathf.Abs(x) > Mathf.Abs(y)) { //Left or Right if (x < 0) {//Left SwipeEvent?.Invoke(Enums.Direction.Left); } else {//Right SwipeEvent?.Invoke(Enums.Direction.Right); } } else { //Up or Down if (y < 0) {//Down SwipeEvent?.Invoke(Enums.Direction.Down); } else {//Up SwipeEvent?.Invoke(Enums.Direction.Up); } } startTouch = swipeDelta = Vector2.zero; } else { if (tap) { TapEvent?.Invoke(); } } }
private void OnSwipeBottom() { AvatarManager.Instance.SwitchToNextPerspective(); OnSwipeDownEvent.Invoke(); }
private void OnSwipeTop() { //add some functionality in the future? OnSwipeTopEvent.Invoke(); }
private void OnSwipeLeft() { AvatarManager.Instance.SwitchToNextAvatar(); OnSwipeLeftEvent.Invoke(); }
void OnSwipeEnd() { SwipeEvent?.Invoke(m_touchStartPosition, m_touchEndPosition); }