public void OnPointerDown(PointerEventData eventData)
 {
     StartTimer();
     _pointerDown               = true;
     _activeGestureData         = new InputGestureData();
     _activeGestureData.Gesture = InputGesture.Unknown;
     _pointerDownPos            = eventData.position;
 }
 private void ResetGesture()
 {
     ResetTimer();
     _activeGestureData = new InputGestureData();
     _tapCandidate      = true;
     _holdCandidate     = true;
     _swipeCandidate    = false;
 }
    public void OnPointerUp(PointerEventData eventData)
    {
        var stopTimer = StopTimer();

        if (stopTimer >= _tapTime)
        {
            _tapCandidate = false;
        }

        if (stopTimer <= _holdTime)
        {
            _holdCandidate = false;
        }

        if (stopTimer >= _swipeTime)
        {
            _swipeCandidate = false;
        }


        if (_tapCandidate)
        {
            _activeGestureData.Gesture = InputGesture.Tap;
        }
        if (_holdCandidate)
        {
            _activeGestureData.Gesture = InputGesture.Hold;
        }
        if (_swipeCandidate)
        {
            _endDragPos = eventData.position;
            _activeGestureData.Gesture = InputGesture.Swipe;
        }

        LastGesture = _activeGestureData;
        ResetGesture();
    }
Пример #4
0
    public bool CheckGesture(Vector3 vGestureVector)
    {
        Vector3 vDirection     = Vector3.zero;
        int     iTrasholdAngle = 0;
        bool    bValidAngle    = false;

        if (!m_bStarted)
        {
            for (int i = 0; i < m_aeAtomicGesturesSequence.Length && !m_bStarted; ++i)           //Find a gesture matching in the list
            {
                InputGestureData.GetGestureData((int)m_aeAtomicGesturesSequence[i], out vDirection, out iTrasholdAngle);

                m_bStarted = VectorUtils.IsAngleWithinThreshold(vGestureVector, mk_vUpVector, vDirection, iTrasholdAngle);

                m_iNextGesture = i;
            }

            if (m_bStarted)
            {
                m_iMatchedCount = 1;

                m_fElapsedTime = mk_fMaxTimeBeforeNextAtomic;

                return(true);
            }

            return(false);
        }
        else if (m_iValidationDirection == 0)        //Not yet decided the direction..
        {
            int iNextGestureIndex = (m_iNextGesture + 1) % m_aeAtomicGesturesSequence.Length;

            InputGestureData.GetGestureData((int)m_aeAtomicGesturesSequence[iNextGestureIndex], out vDirection, out iTrasholdAngle);

            if (VectorUtils.IsAngleWithinThreshold(vGestureVector, mk_vUpVector, vDirection, iTrasholdAngle))
            {
                m_iNextGesture         = iNextGestureIndex;
                m_iValidationDirection = 1;
                m_fElapsedTime         = mk_fMaxTimeBeforeNextAtomic;

                ++m_iMatchedCount;
                return(true);
            }
            else
            {
                iNextGestureIndex = ((m_iNextGesture - 1 >= 0) ? (m_iNextGesture - 1) : (m_aeAtomicGesturesSequence.Length - 1));

                InputGestureData.GetGestureData((int)m_aeAtomicGesturesSequence[iNextGestureIndex], out vDirection, out iTrasholdAngle);

                if (VectorUtils.IsAngleWithinThreshold(vGestureVector, mk_vUpVector, vDirection, iTrasholdAngle))
                {
                    m_iNextGesture         = iNextGestureIndex;
                    m_iValidationDirection = -1;
                    m_fElapsedTime         = mk_fMaxTimeBeforeNextAtomic;

                    ++m_iMatchedCount;
                    return(true);
                }
            }

            return(false);
        }
        else
        {
            int iNextGestureToCheck = m_iNextGesture;
            //Check the gesture in the direction i'm going..
            if (m_iValidationDirection == 1)            //I'm going right
            {
                iNextGestureToCheck = (m_iNextGesture + 1) % m_aeAtomicGesturesSequence.Length;
            }
            else
            {
                iNextGestureToCheck = ((m_iNextGesture - 1 >= 0) ? (m_iNextGesture - 1) : (m_aeAtomicGesturesSequence.Length - 1));
            }

            InputGestureData.GetGestureData((int)m_aeAtomicGesturesSequence[iNextGestureToCheck], out vDirection, out iTrasholdAngle);

            if (VectorUtils.IsAngleWithinThreshold(vGestureVector, mk_vUpVector, vDirection, iTrasholdAngle))
            {
                m_fElapsedTime = mk_fMaxTimeBeforeNextAtomic;
                ++m_iMatchedCount;

                m_iNextGesture = iNextGestureToCheck;

                return(true);
            }
        }

        return(false);
    }