Exemplo 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;
    }
        public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
        {
            if (e1 == null)
            {
                e1 = mLastOnDownEvent;
            }

            float diffY = e2.GetY() - e1.GetY();
            float diffX = e2.GetX() - e1.GetX();

            if (Math.Abs(diffX) > Math.Abs(diffY))
            {
                if (Math.Abs(diffX) > SWIPE_THRESHOLD && Math.Abs(velocityX) > SWIPE_VELOCITY_THRESHOLD)
                {
                    if (diffX > 0)
                    {
                        OnSwipeRight?.Invoke(this, null);
                    }
                    else
                    {
                        OnSwipeLeft?.Invoke(this, null);
                    }
                }
            }

            return(base.OnFling(e1, e2, velocityX, velocityY));
        }
Exemplo n.º 3
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();
                }
            }
        }
    }
Exemplo n.º 4
0
    /*
     * Called by an event from the swipe script.
     * This triggers the computation of the results for swiping RIGHT and afterward the spawning of a new card.
     */
    public void onRightSwipe()
    {
        result res = Results.resultRight;

        computeResult(res);
        OnSwipeRight.Invoke();
    }
Exemplo n.º 5
0
 public void InvokeSwipeRightEvent(object sender, object item)
 {
     if (OnSwipeRight != null)
     {
         OnSwipeRight.Invoke(sender, new EventArgs());
     }
 }
Exemplo n.º 6
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();
            }
        }
    }
Exemplo n.º 7
0
 /*
  * Called by an event from the swipe script.
  * This triggers the computation of the results for swiping DOWN and afterward the spawning of a new card.
  * For compatibility: The execution is discarded if the swipe type is not configured for four directions.
  */
 public void onDownSwipe()
 {
     if (swipeType == E_SwipeType.FourDirection)
     {
         result res = Results.resultDown;
         computeResult(res);
         OnSwipeRight.Invoke();
     }
 }
    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();
            }
        }
    }
Exemplo n.º 9
0
            public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
            {
                bool result = false;

                try
                {
                    float diffY = e2.GetY() - e1.GetY();
                    float diffX = e2.GetX() - e1.GetX();
                    if (Math.Abs(diffX) > Math.Abs(diffY))
                    {
                        if (Math.Abs(diffX) > SWIPE_THRESHOLD && Math.Abs(velocityX) > SWIPE_VELOCITY_THRESHOLD)
                        {
                            if (diffX > 0)
                            {
                                OnSwipeRight?.Invoke();
                            }
                            else
                            {
                                OnSwipeLeft?.Invoke();
                            }
                            result = true;
                        }
                    }
                    else if (Math.Abs(diffY) > SWIPE_THRESHOLD && Math.Abs(velocityY) > SWIPE_VELOCITY_THRESHOLD)
                    {
                        if (diffY > 0)
                        {
                            OnSwipeBottom?.Invoke();
                        }
                        else
                        {
                            OnSwipeTop?.Invoke();
                        }

                        result = true;
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }


                return(result);
            }
Exemplo n.º 10
0
    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);
    }
        public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
        {
            float diffY = e2.GetY() - e1.GetY();
            float diffX = e2.GetX() - e1.GetX();

            if (!(Math.Abs(diffX) > Math.Abs(diffY)))
            {
                return(base.OnFling(e1, e2, velocityX, velocityY));
            }

            if (Math.Abs(diffX) > _swipeThreshold && Math.Abs(velocityX) > _swipeVelocityThreshold)
            {
                if (diffX > 0)
                {
                    OnSwipeRight?.Invoke(this, null);
                }
                else
                {
                    OnSwipeLeft?.Invoke(this, null);
                }
            }

            return(base.OnFling(e1, e2, velocityX, velocityY));
        }
Exemplo n.º 12
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);
 }
Exemplo n.º 13
0
 public void RaiseOnSwipeRight(Location startSwipeLocation = null) => OnSwipeRight?.Invoke(startSwipeLocation ?? CurrentVerseLocation);
Exemplo n.º 14
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;
                }
            }
        }
    }
Exemplo n.º 15
0
 public static void RaiseSwipeRight(object sender)
 {
     OnSwipeRight?.Invoke(sender, EventArgs.Empty);
 }
Exemplo n.º 16
0
 private void SwipeTouchListenerOnOnSwipeRight() => OnSwipeRight?.Invoke(_startSwipeLocation);
Exemplo n.º 17
0
    public void DoUpdate()
    {
        if (Input.touchCount == 1)         // user is touching the screen with a single touch
        {
            var touch = Input.GetTouch(0); // get the touch
            switch (touch.phase)
            {
            //check for the first touch
            case TouchPhase.Began:
                _fp = touch.position;
                _lp = touch.position;
                break;

            // update the last position based on where they moved
            case TouchPhase.Moved:
                _lp = touch.position;
                break;

            //check if the finger is removed from the screen
            case TouchPhase.Ended:
            {
                _lp = touch.position;                         //last touch position. Ommitted if you use list

                //Check if drag distance is greater than 20% of the screen height
                if (Mathf.Abs(_lp.x - _fp.x) > _dragDistance || Mathf.Abs(_lp.y - _fp.y) > _dragDistance)
                {
                    //It's a drag
                    //check if the drag is vertical or horizontal
                    if (Mathf.Abs(_lp.x - _fp.x) > Mathf.Abs(_lp.y - _fp.y))
                    {
                        //If the horizontal movement is greater than the vertical movement...
                        if ((_lp.x > _fp.x))                                 //If the movement was to the right)
                        {
                            //Right swipe
                            OnSwipeRight?.Invoke();
                        }
                        else
                        {
                            OnSwipeLeft?.Invoke();
                            //Left swipe
                        }
                    }
                    else
                    {
                        //the vertical movement is greater than the horizontal movement
                        if (_lp.y > _fp.y)                                 //If the movement was up
                        {
                            //Up swipe
                            OnSwipeUP?.Invoke();
                        }
                        else
                        {
                            OnSwipeDown?.Invoke();
                            //Down swipe
                        }
                    }
                }
                else
                {
                    OnTap?.Invoke();
                    //It's a tap as the drag distance is less than 20% of the screen height
                    Debug.Log("Tap");
                }

                break;
            }
            }
        }
    }