Ejemplo n.º 1
0
    public void OnPointerUp(PointerEventData eventData)
    {
        Vector2 direction = eventData.position - startDragPos;

        if (Math.Abs(direction.x) < minDistanceForSwipe && Math.Abs(direction.y) < minDistanceForSwipe)
        {
            OnTap?.Invoke();
            return;
        }

        if (Math.Abs(direction.x) >= Math.Abs(direction.y))
        {
            if (startDragPos.x < eventData.position.x)
            {
                OnSwipeRight?.Invoke();
            }
            else
            {
                OnSwipeLeft?.Invoke();
            }
        }
        else
        {
            if (startDragPos.y < eventData.position.y)
            {
                OnSwipeUp?.Invoke();
            }
            else
            {
                OnSwipeDown?.Invoke();
            }
        }
        startDragPos = Vector2.zero;
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //check if there is a touch found
        if (Input.touchCount > 0)
        {
            playerTouch = Input.GetTouch(0);

            if (playerTouch.phase == TouchPhase.Began)
            {
                initialTouchPosition = playerTouch.position;
            }
            else if (playerTouch.phase == TouchPhase.Ended || playerTouch.phase == TouchPhase.Canceled)
            {
                finalTouchPosition = playerTouch.position;
                direction          = DetectSwipeDirection(initialTouchPosition, finalTouchPosition);
                if (direction == SwipeDirection.Left)
                {
                    OnSwipeLeft?.Invoke();
                }
                else if (direction == SwipeDirection.Right)
                {
                    OnSwipeRight?.Invoke();
                }
                else if (direction == SwipeDirection.Up)
                {
                    OnSwipeUp?.Invoke();
                }
                else if (direction == SwipeDirection.Down)
                {
                    OnSwipeDown?.Invoke();
                }
            }
        }
    }
    protected override void SwipeDetection()
    {
        if (Input.GetMouseButtonDown(0))
        {
            lastPosition = firstPosition;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            lastPosition = Input.mousePosition;

            if (Mathf.Abs(lastPosition.y - firstPosition.y) > dragDistance)
            {
                if (lastPosition.y > firstPosition.y)
                {
                    OnSwipeUp?.Invoke();
                }
                else
                {
                    OnSwipeDown?.Invoke();
                }

                Debug.Log("OnSwipe");
                OnSwipe?.Invoke();
            }
            else
            {
                Debug.Log("Tap");
            }

            OnResetPosition();
        }
    }
Ejemplo n.º 4
0
    //Checking and calling respective delegate events
    void SwipeInputs()
    {
        if (swipeManager.SwipeUp && canSwipe)
        {
            canSwipe = false;

            //Calling delegate event
            if (OnSwipeUp != null)
            {
                OnSwipeUp.Invoke();
            }
        }
        else if (swipeManager.SwipeRight && canSwipe)
        {
            canSwipe = false;

            //Calling delegate event
            if (OnSwipeRight != null)
            {
                OnSwipeRight.Invoke();
            }
        }
        else if (swipeManager.SwipeDown && canSwipe)
        {
            canSwipe = false;

            //Calling delegate event
            if (OnSwipeDown != null)
            {
                OnSwipeDown.Invoke();
            }
        }
        else if (swipeManager.SwipeLeft && canSwipe)
        {
            canSwipe = false;

            //Calling delegate event
            if (OnSwipeLeft != null)
            {
                OnSwipeLeft.Invoke();
            }
        }
        else if (swipeManager.Tap)
        {
            //Calling delegate event
            if (OnSingleTap != null)
            {
                OnSingleTap.Invoke();
            }
        }
        else if (swipeManager.DoubleTap)
        {
            //Calling delegate event
            if (OnDoubleTap != null)
            {
                OnDoubleTap.Invoke();
            }
        }
    }
Ejemplo n.º 5
0
    protected override void SwipeDetection()
    {
        if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                firstPosition = touch.position;
                lastPosition  = touch.position;
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                lastPosition = touch.position;
                isTouchMoved = true;
            }
            else if (touch.phase == TouchPhase.Ended)
            {
                firstPosition = touch.position;

                if (Mathf.Abs(lastPosition.y - firstPosition.y) > dragDistance)
                {
                    if (isTouchMoved)
                    {
                        if (lastPosition.y > firstPosition.y)
                        {
                            OnSwipeUp?.Invoke();
                        }
                        else
                        {
                            OnSwipeDown?.Invoke();
                        }

                        OnSwipe?.Invoke();
                        isTouchMoved = false;
                    }
                }
            }
            else
            {
                Debug.Log("Tap");
            }

            OnResetPosition();
        }
    }
    public void Update(float deltaTime)
    {
        if (VRInput.GetControl(handType, ControlType.PadTouch))
        {
            if (VRInput.GetControlDown(handType, ControlType.PadTouch))
            {
                isSwiping = true;
                timeout   = pipelineManager.New().Delay(timeoutSec).Func(Reset);
                return;
            }

            if (isSwiping)
            {
                Vector2 delta = VRInput.PadTouchDelta(handType);
                deltaX += delta.x;
                deltaY += delta.y;
            }
        }

        if (VRInput.GetControlUp(handType, ControlType.PadTouch))
        {
            if (isSwiping)
            {
                if (deltaX > swipeThreshold)
                {
                    OnSwipeRight?.Invoke(deltaX);
                }
                else if (deltaX < -swipeThreshold)
                {
                    OnSwipeLeft?.Invoke(deltaX);
                }

                if (deltaY > swipeThreshold)
                {
                    OnSwipeUp?.Invoke(deltaX);
                }
                else if (deltaY < -swipeThreshold)
                {
                    OnSwipeDown?.Invoke(deltaX);
                }

                Reset();
            }
        }
    }
Ejemplo n.º 7
0
 public void CompareByNormalizedFloat()
 {
     if (offSet.x > swipeDetectionLimitLeftRight && enableHorizontalSwipe)
     {
         OnSwipeRight?.Invoke(this, EventArgs.Empty);
         return;
     }
     if (offSet.x < swipeDetectionLimitLeftRight && enableHorizontalSwipe)
     {
         OnSwipeLeft?.Invoke(this, EventArgs.Empty);
         return;
     }
     if (offSet.y > swipeDetectionLimitUpDown && enableVerticalSwipe)
     {
         OnSwipeUp?.Invoke(this, EventArgs.Empty);
         return;
     }
     if (offSet.y < swipeDetectionLimitUpDown && enableVerticalSwipe)
     {
         OnSwipeDown?.Invoke(this, EventArgs.Empty);
         return;
     }
     OnSwipeCancel?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 8
0
    public void Update()
    {
        //Dont check inputs when dead or not running
        if (!manager.isGameStarted || manager.isDead)
        {
            return;
        }

        //Reset swipe status to prevent multiple event triggers
        swipedRight = false;
        swipedLeft  = false;
        swipedUp    = false;
        swipedDown  = false;

        if (Input.touches.Length > 0)
        {
            t = Input.GetTouch(0);

            if (t.phase == TouchPhase.Began)
            {
                //Look for single taps when in a boss fight
                if (t.position.y > Screen.height / 2f && manager.bossActive)
                {
                    OnSingleTap.Invoke();
                    return;
                }

                startPos = new Vector2(t.position.x / Screen.width, t.position.y / Screen.width);
                tapCount++;
            }
            else if (t.phase == TouchPhase.Moved && !swiped)
            {
                endPos = new Vector2(t.position.x / Screen.width, t.position.y / Screen.width);
                swipe  = new Vector2(endPos.x - startPos.x, endPos.y - startPos.y);

                // Too short swipe
                if (swipe.magnitude < MIN_SWIPE_DISTANCE)
                {
                    return;
                }

                swiped = true;

                if (Mathf.Abs(swipe.x) > Mathf.Abs(swipe.y))
                {
                    // Horizontal swipe
                    if (swipe.x > 0)
                    {
                        swipedRight = true;
                        OnSwipeRight.Invoke();
                    }
                    else
                    {
                        swipedLeft = true;
                        OnSwipeLeft.Invoke();
                    }
                }
                else
                {
                    // Vertical swipe
                    if (swipe.y > 0)
                    {
                        swipedUp = true;
                        OnSwipeUp.Invoke();
                    }
                    else
                    {
                        swipedDown = true;
                        OnSwipeDown.Invoke();
                    }
                }
            }
            else if (t.phase == TouchPhase.Ended)
            {
                swiped = false;
            }
        }

        //Too long for double tap
        if (doubleTapTimer > MAX_DOUBLE_TAP_TIME)
        {
            doubleTapTimer = 0f;
            tapCount       = 0;
        }
        //Double tap
        else if (tapCount >= 2)
        {
            doubleTapTimer = 0.0f;
            tapCount       = 0;
            OnDoubleTap.Invoke();
        }
        //Increase double tap timer
        else if (tapCount > 0)
        {
            doubleTapTimer += Time.deltaTime;
        }

        //If debugging, look for keyboard inputs
        if (debugWithArrowKeys)
        {
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                OnSwipeRight.Invoke();
            }
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                OnSwipeLeft.Invoke();
            }
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                OnSwipeUp.Invoke();
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                OnSwipeDown.Invoke();
            }
            if (Input.GetKeyDown(KeyCode.E))
            {
                OnSingleTap.Invoke();
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                OnDoubleTap.Invoke();
            }
        }
    }
Ejemplo n.º 9
0
    private void Update()
    {
        //Check Device Orientation Maybe use DougMcFarlane Device Change class from https://forum.unity.com/threads/device-screen-rotation-event.118638/
        if (Input.deviceOrientation == DeviceOrientation.Portrait)
        {
            //Run all methods subscribed to event
            OnOrientationPortrait?.Invoke();
        }
        else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft || Input.deviceOrientation == DeviceOrientation.LandscapeRight)
        {
            OnOrientationLandscape?.Invoke();
        }

        //check if there is a touch found
        if (Input.touchCount > 0)
        {
            initialPlayerTouch = Input.GetTouch(0);
            //Test to see if this will cause any issues.
            //OnTouchDrag?.Invoke(initialPlayerTouch);
            touchTimer += Time.deltaTime;

            //check if we are touching a UI element and if we are dont do any input commands !!!MOVE INTO TOUCHPHASE.ENDED IF
            if (IsTouchOverUIElement(initialPlayerTouch) == false)
            {
                if (initialPlayerTouch.phase == TouchPhase.Began)
                {
                    initialTouchPosition = initialPlayerTouch.position;
                }
                else if (initialPlayerTouch.phase == TouchPhase.Moved)
                {
                    OnTouchDrag?.Invoke(initialPlayerTouch);
                }
                else if (initialPlayerTouch.phase == TouchPhase.Ended)
                {
                    finalTouchPosition = initialPlayerTouch.position;
                    touchTimer         = touchTimer;

                    direction = DetectSwipeDirection(initialTouchPosition, finalTouchPosition);
                    if (direction == SwipeDirection.Left)
                    {
                        OnSwipeLeft?.Invoke();
                    }
                    else if (direction == SwipeDirection.Right)
                    {
                        OnSwipeRight?.Invoke();
                    }
                    else if (direction == SwipeDirection.Up)
                    {
                        OnSwipeUp?.Invoke();
                    }
                    else if (direction == SwipeDirection.Down)
                    {
                        OnSwipeDown?.Invoke();
                    }
                    else if (direction == SwipeDirection.None)
                    {
                        if (touchTimer < tapTime)
                        {
                            StartCoroutine("DoubleTap");
                        }
                        else
                        {
                            OnSingleTouchHeld?.Invoke(initialPlayerTouch);
                        }
                    }
                    touchTimer = 0f;
                }
            }
        }
    }
Ejemplo n.º 10
0
 public static void RaiseSwipeUp(object sender)
 {
     OnSwipeUp?.Invoke(sender, EventArgs.Empty);
 }