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;
    }
Exemplo n.º 2
0
 public void InvokeSwipeLeftEvent(object sender, object item)
 {
     if (OnSwipeLeft != null)
     {
         OnSwipeLeft.Invoke(sender, new EventArgs());
     }
 }
        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.º 4
0
    /*
     * Called by an event from the swipe script.
     * This triggers the computation of the results for swiping LEFT and afterward the spawning of a new card.
     */
    public void onLeftSwipe()
    {
        result res = Results.resultLeft;

        computeResult(res);
        OnSwipeLeft.Invoke();
    }
Exemplo n.º 5
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.º 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();
            }
        }
    }
    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.º 8
0
 private void CompareSwipeDirectionUsingPixel()
 {
     if (offSet.x > swipeDetectionLimitLeftRight)
     {
         swipedRight.Invoke();
     }
     if (offSet.x < -swipeDetectionLimitLeftRight)
     {
         //swipedLeft.Invoke();
         OnSwipeLeft?.Invoke();
     }
     if (offSet.y > swipeDetectionLimitUpDown)
     {
         swipedUp.Invoke();
     }
     if (offSet.y < -swipeDetectionLimitUpDown)
     {
         swipedDown.Invoke();
     }
 }
Exemplo n.º 9
0
 private void CompareNormalizedFloatToSwipeDirection()
 {
     if (_normalizeValueX > swipeDetectionLimitLeftRight)
     {
         swipedRight.Invoke();
     }
     if (_normalizeValueX < -swipeDetectionLimitLeftRight)
     {
         //swipedLeft.Invoke();
         OnSwipeLeft?.Invoke();
     }
     if (_normalizeValueY > swipeDetectionLimitUpDown)
     {
         swipedUp.Invoke();
     }
     if (_normalizeValueY < -swipeDetectionLimitUpDown)
     {
         swipedDown.Invoke();
     }
 }
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 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();
            }
        }
    }
Exemplo n.º 14
0
 public void RaiseOnSwipeLeft(Location startSwipeLocation  = null) => OnSwipeLeft?.Invoke(startSwipeLocation ?? CurrentVerseLocation);
Exemplo n.º 15
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.º 16
0
 private void SwipeTouchListenerOnOnSwipeLeft() => OnSwipeLeft?.Invoke(_startSwipeLocation);
Exemplo n.º 17
0
 public static void RaiseSwipeLeft(object sender)
 {
     OnSwipeLeft?.Invoke(sender, EventArgs.Empty);
 }