/// <inheritdoc />
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(fingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(fingerId2))
            {
                Cancel();
                return(false);
            }

            var foundTouches = GestureTouchesUtility.TryFindTouch(fingerId1, out var touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(fingerId2, out var touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that both fingers are moving.
            if (touch1.deltaPosition == Vector2.zero || touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            var rotation = CalculateDeltaRotation(
                touch1.position, touch2.position, startPosition1, startPosition2);

            return(Mathf.Abs(rotation) >= twistRecognizer.slopRotation);
        }
        /// <summary>
        /// Returns true if this gesture can start.
        /// </summary>
        /// <returns>True if the gesture can start.</returns>
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(FingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(FingerId2))
            {
                Cancel();
                return(false);
            }

            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(FingerId2, out touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that at least one finger is moving.
            if (touch1.deltaPosition == Vector2.zero && touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            PinchGestureRecognizer pinchRecognizer = m_Recognizer as PinchGestureRecognizer;

            Vector3 firstToSecondDirection = (StartPosition1 - StartPosition2).normalized;
            float   dot1         = Vector3.Dot(touch1.deltaPosition.normalized, -firstToSecondDirection);
            float   dot2         = Vector3.Dot(touch2.deltaPosition.normalized, firstToSecondDirection);
            float   dotThreshold =
                Mathf.Cos(pinchRecognizer.m_SlopMotionDirectionDegrees * Mathf.Deg2Rad);

            // Check angle of motion for the first touch.
            if (touch1.deltaPosition != Vector2.zero && Mathf.Abs(dot1) < dotThreshold)
            {
                return(false);
            }

            // Check angle of motion for the second touch.
            if (touch2.deltaPosition != Vector2.zero && Mathf.Abs(dot2) < dotThreshold)
            {
                return(false);
            }

            float startgap = (StartPosition1 - StartPosition2).magnitude;

            Gap = (touch1.position - touch2.position).magnitude;
            float separation = GestureTouchesUtility.PixelsToInches(Mathf.Abs(Gap - startgap));

            if (separation < pinchRecognizer.m_SlopInches)
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Returns true if this gesture can start.
        /// </summary>
        /// <returns>Returns <see langword="true"/> if the gesture can start. Returns <see langword="false"/> otherwise.</returns>
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(fingerId))
            {
                Cancel();
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Returns true if this gesture can start.
        /// </summary>
        /// <returns>True if the gesture can start.</returns>
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(FingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(FingerId2))
            {
                Cancel();
                return(false);
            }

            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(FingerId2, out touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that at least one finger is moving.
            if (touch1.deltaPosition == Vector2.zero && touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            Vector2 pos1       = touch1.position;
            float   diff1      = (pos1 - StartPosition1).magnitude;
            Vector2 pos2       = touch2.position;
            float   diff2      = (pos2 - StartPosition2).magnitude;
            float   slopInches = (m_Recognizer as TwoFingerDragGestureRecognizer).m_SlopInches;

            if (GestureTouchesUtility.PixelsToInches(diff1) < slopInches ||
                GestureTouchesUtility.PixelsToInches(diff2) < slopInches)
            {
                return(false);
            }

            TwoFingerDragGestureRecognizer recognizer =
                m_Recognizer as TwoFingerDragGestureRecognizer;

            // Check both fingers move in the same direction.
            float dot =
                Vector3.Dot(touch1.deltaPosition.normalized, touch2.deltaPosition.normalized);

            if (dot < Mathf.Cos(recognizer.m_AngleThresholdRadians))
            {
                return(false);
            }

            return(true);
        }
 void TryCreateOneFingerGestureOnTouchBegan(Func <CommonTouch, T> createGestureFunction)
 {
     foreach (var touch in GestureTouchesUtility.touches)
     {
         if (touch.isPhaseBegan &&
             !GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) &&
             !GestureTouchesUtility.IsTouchOffScreenEdge(touch))
         {
             var gesture = createGestureFunction(touch);
             AddGesture(gesture);
         }
     }
 }
        /// <inheritdoc />
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(fingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(fingerId2))
            {
                Cancel();
                return(false);
            }

            var foundTouches = GestureTouchesUtility.TryFindTouch(fingerId1, out var touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(fingerId2, out var touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that at least one finger is moving.
            if (touch1.deltaPosition == Vector2.zero && touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            Vector3 firstToSecondDirection = (startPosition1 - startPosition2).normalized;
            var     dot1         = Vector3.Dot(touch1.deltaPosition.normalized, -firstToSecondDirection);
            var     dot2         = Vector3.Dot(touch2.deltaPosition.normalized, firstToSecondDirection);
            var     dotThreshold = Mathf.Cos(pinchRecognizer.slopMotionDirectionDegrees * Mathf.Deg2Rad);

            // Check angle of motion for the first touch.
            if (touch1.deltaPosition != Vector2.zero && Mathf.Abs(dot1) < dotThreshold)
            {
                return(false);
            }

            // Check angle of motion for the second touch.
            if (touch2.deltaPosition != Vector2.zero && Mathf.Abs(dot2) < dotThreshold)
            {
                return(false);
            }

            var startgap = (startPosition1 - startPosition2).magnitude;

            gap = (touch1.position - touch2.position).magnitude;
            var separation = GestureTouchesUtility.PixelsToInches(Mathf.Abs(gap - startgap));

            return(separation >= pinchRecognizer.slopInches);
        }
 /// <summary>
 /// Helper function for creating one finger gestures when a touch begins.
 /// </summary>
 /// <param name="createGestureFunction">Function to be executed to create the gesture.</param>
 protected internal void TryCreateOneFingerGestureOnTouchBegan(
     Func <Touch, T> createGestureFunction)
 {
     for (int i = 0; i < GestureTouchesUtility.Touches.Length; i++)
     {
         Touch touch = GestureTouchesUtility.Touches[i];
         if (touch.phase == TouchPhase.Began &&
             !GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) &&
             !GestureTouchesUtility.IsTouchOffScreenEdge(touch))
         {
             T gesture = createGestureFunction(touch);
             gesture.onStart    += OnStart;
             gesture.onFinished += OnFinished;
             m_Gestures.Add(gesture);
         }
     }
 }
        void TryCreateGestureTwoFingerGestureOnTouchBeganForTouchIndex(
            int touchIndex,
            Func <Touch, Touch, T> createGestureFunction)
        {
            if (GestureTouchesUtility.Touches[touchIndex].phase != TouchPhase.Began)
            {
                return;
            }

            var touch = GestureTouchesUtility.Touches[touchIndex];

            if (GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) ||
                GestureTouchesUtility.IsTouchOffScreenEdge(touch))
            {
                return;
            }

            for (var i = 0; i < GestureTouchesUtility.Touches.Length; i++)
            {
                if (i == touchIndex)
                {
                    continue;
                }

                // Prevents the same two touches from creating two gestures if both touches began on
                // the same frame.
                if (i < touchIndex && GestureTouchesUtility.Touches[i].phase == TouchPhase.Began)
                {
                    continue;
                }

                var otherTouch = GestureTouchesUtility.Touches[i];
                if (GestureTouchesUtility.IsFingerIdRetained(otherTouch.fingerId) ||
                    GestureTouchesUtility.IsTouchOffScreenEdge(otherTouch))
                {
                    continue;
                }

                var gesture = createGestureFunction(touch, otherTouch);
                gesture.onStart    += OnStart;
                gesture.onFinished += OnFinished;
                m_Gestures.Add(gesture);
            }
        }
        /// <inheritdoc />
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(fingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(fingerId2))
            {
                Cancel();
                return(false);
            }

            var foundTouches = GestureTouchesUtility.TryFindTouch(fingerId1, out var touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(fingerId2, out var touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that at least one finger is moving.
            if (touch1.deltaPosition == Vector2.zero && touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            var pos1       = touch1.position;
            var diff1      = (pos1 - startPosition1).magnitude;
            var pos2       = touch2.position;
            var diff2      = (pos2 - startPosition2).magnitude;
            var slopInches = dragRecognizer.slopInches;

            if (GestureTouchesUtility.PixelsToInches(diff1) < slopInches ||
                GestureTouchesUtility.PixelsToInches(diff2) < slopInches)
            {
                return(false);
            }

            // Check both fingers move in the same direction.
            var dot = Vector3.Dot(touch1.deltaPosition.normalized, touch2.deltaPosition.normalized);

            return(dot >= Mathf.Cos(dragRecognizer.angleThresholdRadians));
        }
Exemple #10
0
        /// <summary>
        /// Returns true if this gesture can start.
        /// </summary>
        /// <returns>True if the gesture can start.</returns>
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(FingerId))
            {
                Cancel();
                return(false);
            }

            if (GestureTouchesUtility.Touches.Length > 1)
            {
                for (int i = 0; i < GestureTouchesUtility.Touches.Length; i++)
                {
                    Touch currentTouch = GestureTouchesUtility.Touches[i];
                    if (currentTouch.fingerId != FingerId &&
                        !GestureTouchesUtility.IsFingerIdRetained(currentTouch.fingerId))
                    {
                        return(false);
                    }
                }
            }

            Touch touch;

            if (GestureTouchesUtility.TryFindTouch(FingerId, out touch))
            {
                Vector2 pos  = touch.position;
                float   diff = (pos - StartPosition).magnitude;
                if (GestureTouchesUtility.PixelsToInches(diff) >=
                    (m_Recognizer as DragGestureRecognizer).m_SlopInches)
                {
                    return(true);
                }
            }
            else
            {
                Cancel();
            }

            return(false);
        }
        void TryCreateGestureTwoFingerGestureOnTouchBeganForTouchIndex(
            int touchIndex,
            IReadOnlyList <CommonTouch> touches,
            Func <CommonTouch, CommonTouch, T> createGestureFunction)
        {
            var touch = touches[touchIndex];

            if (!touch.isPhaseBegan ||
                GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) ||
                GestureTouchesUtility.IsTouchOffScreenEdge(touch))
            {
                return;
            }

            for (var i = 0; i < touches.Count; i++)
            {
                if (i == touchIndex)
                {
                    continue;
                }

                var otherTouch = touches[i];

                // Prevents the same two touches from creating two gestures if both touches began on
                // the same frame.
                if (i < touchIndex && otherTouch.isPhaseBegan)
                {
                    continue;
                }

                if (GestureTouchesUtility.IsFingerIdRetained(otherTouch.fingerId) ||
                    GestureTouchesUtility.IsTouchOffScreenEdge(otherTouch))
                {
                    continue;
                }

                var gesture = createGestureFunction(touch, otherTouch);
                AddGesture(gesture);
            }
        }
Exemple #12
0
        /// <summary>
        /// Returns true if this gesture can start.
        /// </summary>
        /// <returns>True if the gesture can start.</returns>
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(FingerId1) ||
                GestureTouchesUtility.IsFingerIdRetained(FingerId2))
            {
                Cancel();
                return(false);
            }

            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

            foundTouches =
                GestureTouchesUtility.TryFindTouch(FingerId2, out touch2) && foundTouches;

            if (!foundTouches)
            {
                Cancel();
                return(false);
            }

            // Check that both fingers are moving.
            if (touch1.deltaPosition == Vector2.zero || touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            TwistGestureRecognizer twistRecognizer = m_Recognizer as TwistGestureRecognizer;

            float rotation = CalculateDeltaRotation(
                touch1.position, touch2.position, StartPosition1, StartPosition2);

            if (Mathf.Abs(rotation) < twistRecognizer.m_SlopRotation)
            {
                return(false);
            }

            return(true);
        }
#pragma warning restore IDE1006

        /// <inheritdoc />
        protected internal override bool CanStart()
        {
            if (GestureTouchesUtility.IsFingerIdRetained(fingerId))
            {
                Cancel();
                return(false);
            }

            var touches = GestureTouchesUtility.touches;

            if (touches.Count > 1)
            {
                foreach (var currentTouch in touches)
                {
                    if (currentTouch.fingerId != fingerId &&
                        !GestureTouchesUtility.IsFingerIdRetained(currentTouch.fingerId))
                    {
                        return(false);
                    }
                }
            }

            if (GestureTouchesUtility.TryFindTouch(fingerId, out var touch))
            {
                var pos  = touch.position;
                var diff = (pos - startPosition).magnitude;
                if (GestureTouchesUtility.PixelsToInches(diff) >= dragRecognizer.slopInches)
                {
                    return(true);
                }
            }
            else
            {
                Cancel();
            }

            return(false);
        }