private void HandleDoubleTap()
    {
        if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);

            if (touch.position.x > GameManager.Instance.screenWidth * controlAreaSize / 2 &&
                touch.position.x < GameManager.Instance.screenWidth - GameManager.Instance.screenWidth * controlAreaSize / 2 &&
                touch.phase == TouchPhase.Began)
            {
                tapCount++;
            }

            if (tapCount == 1)
            {
                tapTime = Time.time + maxDoubleTapDuration;
            }
            else if (tapCount == 2 && Time.time < tapTime)
            {
                if ((lastTouch.position - touch.position).magnitude < doubleTapVariance * Screen.dpi)
                {
                    OnDoubleTap?.Invoke();
                }

                tapCount = 0;
            }

            if (Time.time > tapTime)
            {
                tapCount = 0;
            }

            lastTouch = touch;
        }
    }
    public override void OnPointerDown(PointerEventData ea)
    {
        _handleAnchorPos = ea.position;
        Handle.anchorMin = Handle.anchorMax =
            new Vector2(ea.position.x / _screenWidth, ea.position.y / _screenHeight / _anchorMaxY);

        _indeterminacy     = false;
        _isOnHoldingPushed = false;
        if (_timer == 0)
        {
            _toTick = true;
        }
        if (_timer > 0 && _timer <= DoubleTapTreshold)
        {
            OnDoubleTap?.Invoke();
            //Debug.LogWarning("DOUBLE "+_timer);
            _toTick = false;
            _timer  = 0;
        }
        if (_timer > DoubleTapTreshold)
        {
            _timer = 0;
        }
        OnDrag(ea);
    }
Esempio n. 3
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();
            }
        }
    }
Esempio n. 4
0
    private IEnumerator DoubleTap()
    {
        yield return(new WaitForSeconds(0.2f));

        if (initialPlayerTouch.tapCount == 1)
        {
            Debug.Log("THIS IS A SINGLE TAP");
            OnSingleTouch?.Invoke(initialPlayerTouch);
        }
        else if (initialPlayerTouch.tapCount == 2)
        {
            OnDoubleTap?.Invoke(initialPlayerTouch);
            StopCoroutine("DoubleTap");
            Debug.Log("THIS IS A DOUBLE TAP");
        }
    }
Esempio n. 5
0
    //We trigger double tap and set canTap and canDoubleTap to false so that neither of them triggers consecutively. We return those value back to true by using invoke.
    private void TriggerDoubleTap() //! Called by Function name with string reference
    {
        if (canDoubleTap)
        {
            //Calling delegate event
            if (OnDoubleTap != null)
            {
                OnDoubleTap.Invoke();
            }
        }

        canTap       = false;
        canDoubleTap = false;
        Invoke("ReturnTapToTrue", tapNullifyTimeAfterTrigger);
        Invoke("ReturnDoubleTapToTrue", doubleTapNullifyTimeAfterTrigger);
        doubleTapInitialized = false;
    }
Esempio n. 6
0
 private void UpdateMobile()
 {
     for (var i = 0; i < Input.touchCount; i++)
     {
         if (Input.GetTouch(i).phase == TouchPhase.Began)
         {
             if (Input.GetTouch(i).tapCount == 2)
             {
                 OnDoubleTap?.Invoke();
             }
             if (Input.GetTouch(i).tapCount == 1)
             {
                 OnSingleTap?.Invoke();
             }
         }
     }
 }
Esempio n. 7
0
 private void UpdateEditor()
 {
     if (Input.GetMouseButtonDown(0))
     {
         if (Time.time < _tapTimer + TapThreshold)
         {
             OnDoubleTap?.Invoke();
             _tap = false;
             return;
         }
         _tap      = true;
         _tapTimer = Time.time;
     }
     if (_tap && Time.time > _tapTimer + TapThreshold)
     {
         _tap = false;
         OnSingleTap?.Invoke();
     }
 }
Esempio n. 8
0
 public override void OnPointerDown(PointerEventData eventData)
 {
     _indeterminacy     = false;
     _isOnHoldingPushed = false;
     if (_timer == 0)
     {
         _toTick = true;
     }
     if (_timer > 0 && _timer <= DoubleTapTreshold)
     {
         OnDoubleTap?.Invoke();
         //Debug.LogWarning("DOUBLE "+_timer);
         _toTick = false;
         _timer  = 0;
     }
     if (_timer > DoubleTapTreshold)
     {
         _timer = 0;
     }
     OnDrag(eventData);
 }
Esempio n. 9
0
        private void DetectTapGestures()
        {
            TouchManipulationInfo[] infos = new TouchManipulationInfo[_touchDictionary.Count];
            _touchDictionary.Values.CopyTo(infos, 0);
            if (infos.Length != 1)
            {
                return;
            }
            SKPoint point = infos[0].PreviousPoint;

            if (infos[0].MoveCounter > MaxTapMoveCounter)
            {
                return;
            }
            var tapEventArgs = new TapEventArgs(point);

            var now         = DateTime.Now;
            var lastTapTime = LastTapTime;

            LastTapTime = now;

            OnTap?.Invoke(this, tapEventArgs);
            if (now - lastTapTime < DoubleTapDelay)
            {
                OnDoubleTap?.Invoke(this, tapEventArgs);
                LastDoubleTapTime = now;
                LastTapTime       = DateTime.MinValue; //Reset double tap timer
            }
            else
            {
                _timer = new Timer(_ =>
                {
                    if (DateTime.Now - LastDoubleTapTime < DoubleTapDelay)
                    {
                        return;
                    }
                    OnSingleTap?.Invoke(this, tapEventArgs);
                }, null, DoubleTapDelay.Milliseconds, Timeout.Infinite);
            }
        }
Esempio n. 10
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();
            }
        }
    }