Esempio n. 1
0
    public void OnDrag(PointerEventData eventData)
    {
        if (pointerId == eventData.pointerId)
        {
            Vector2 _touchVector = eventData.position - _startPos;
            if (_touchVector.magnitude > _settings.thresholdMagnitude)
            {
                pointerId = int.MinValue;

                if (_touchVector.x > _touchVector.y)
                {
                    if (Vector3.Dot(_touchVector, Vector3.right) > 0)
                    {
                        OnSwipeRightOccured?.Invoke();
                    }
                    else
                    {
                        OnSwipeLeftOccured?.Invoke();
                    }
                }
                else
                {
                    if (Vector3.Dot(_touchVector, Vector3.up) > 0)
                    {
                        OnSwipeUpOccured?.Invoke();
                    }
                    else
                    {
                        OnSwipeDownOccured?.Invoke();
                    }
                }
            }
        }
    }
Esempio n. 2
0
    private void Update()
    {
        var up    = Input.GetKeyDown(KeyCode.UpArrow);
        var down  = Input.GetKeyDown(KeyCode.DownArrow);
        var left  = Input.GetKeyDown(KeyCode.LeftArrow);
        var right = Input.GetKeyDown(KeyCode.RightArrow);

        if (up)
        {
            OnSwipeUpOccured?.Invoke();
        }
        else if (down)
        {
            OnSwipeDownOccured?.Invoke();
        }
        else if (left)
        {
            OnSwipeLeftOccured?.Invoke();
        }
        else if (right)
        {
            OnSwipeRightOccured?.Invoke();
        }
    }