/// <summary>
        /// Updates this gesture.
        /// </summary>
        /// <returns>True if the update was successful.</returns>
        protected internal override bool UpdateGesture()
        {
            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

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

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

            if (touch1.phase == TouchPhase.Canceled || touch2.phase == TouchPhase.Canceled)
            {
                Cancel();
                return(false);
            }

            if (touch1.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Ended)
            {
                Complete();
                return(false);
            }

            if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved)
            {
                Delta    = ((touch1.position + touch2.position) / 2) - Position;
                Position = (touch1.position + touch2.position) / 2;
                return(true);
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Updates this gesture.
        /// </summary>
        /// <returns>True if the update was successful.</returns>
        protected internal override bool UpdateGesture()
        {
            Touch touch;

            if (GestureTouchesUtility.TryFindTouch(FingerId, out touch))
            {
                if (touch.phase == TouchPhase.Moved)
                {
                    Delta    = touch.position - Position;
                    Position = touch.position;
                    return(true);
                }
                else if (touch.phase == TouchPhase.Ended)
                {
                    Complete();
                }
                else if (touch.phase == TouchPhase.Canceled)
                {
                    Cancel();
                }
            }
            else
            {
                Cancel();
            }

            return(false);
        }
        /// <summary>
        /// Action to be performed when this gesture is started.
        /// </summary>
        protected internal override void OnStart()
        {
            GestureTouchesUtility.LockFingerId(FingerId1);
            GestureTouchesUtility.LockFingerId(FingerId2);

            RaycastHit hit1;
            RaycastHit hit2;

            if (GestureTouchesUtility.RaycastFromCamera(StartPosition1, out hit1))
            {
                var gameObject = hit1.transform.gameObject;
                if (gameObject != null)
                {
                    TargetObject = gameObject.GetComponentInParent <Manipulator>().gameObject;
                }
            }
            else if (GestureTouchesUtility.RaycastFromCamera(StartPosition2, out hit2))
            {
                var gameObject = hit2.transform.gameObject;
                if (gameObject != null)
                {
                    TargetObject = gameObject.GetComponentInParent <Manipulator>().gameObject;
                }
            }

            Touch touch1;

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

            GestureTouchesUtility.TryFindTouch(FingerId2, out touch2);
            Position = (touch1.position + touch2.position) / 2;
        }
Exemple #4
0
        /// <summary>
        /// Updates this gesture.
        /// </summary>
        /// <returns>True if the update was successful.</returns>
        protected internal override bool UpdateGesture()
        {
            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

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

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

            if (touch1.phase == TouchPhase.Canceled || touch2.phase == TouchPhase.Canceled)
            {
                Cancel();
                return(false);
            }

            if (touch1.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Ended)
            {
                Complete();
                return(false);
            }

            if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved)
            {
                float newgap = (touch1.position - touch2.position).magnitude;
                GapDelta = newgap - Gap;
                Gap      = newgap;
                return(true);
            }

            return(false);
        }
Exemple #5
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;
        }
        /// <summary>
        /// Updates this gesture.
        /// </summary>
        /// <returns>True if the update was successful.</returns>
        protected internal override bool UpdateGesture()
        {
            Touch touch;

            if (GestureTouchesUtility.TryFindTouch(FingerId, out touch))
            {
                TapGestureRecognizer tapRecognizer = m_Recognizer as TapGestureRecognizer;
                m_ElapsedTime += touch.deltaTime;
                if (m_ElapsedTime > tapRecognizer.m_TimeSeconds)
                {
                    Cancel();
                }
                else if (touch.phase == TouchPhase.Moved)
                {
                    float diff       = (touch.position - StartPosition).magnitude;
                    float diffInches = GestureTouchesUtility.PixelsToInches(diff);
                    if (diffInches > tapRecognizer.m_SlopInches)
                    {
                        Cancel();
                    }
                }
                else if (touch.phase == TouchPhase.Ended)
                {
                    Complete();
                }
            }
            else
            {
                Cancel();
            }

            return(false);
        }
Exemple #7
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 at least one finger is moving.
            if (touch1.deltaPosition == Vector2.zero && touch2.deltaPosition == Vector2.zero)
            {
                return(false);
            }

            PinchGestureRecognizer pinchRecognizer = 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.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.SlopInches)
            {
                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(FingerId))
            {
                Cancel();
                return(false);
            }

            return(true);
        }
Exemple #9
0
        /// <summary>
        /// Action to be performed when this gesture is started.
        /// </summary>
        protected internal override void OnStart()
        {
            GestureTouchesUtility.LockFingerId(FingerId1);
            GestureTouchesUtility.LockFingerId(FingerId2);

            Touch touch1, touch2;
            GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);
            GestureTouchesUtility.TryFindTouch(FingerId2, out touch2);
            m_PreviousPosition1 = touch1.position;
            m_PreviousPosition2 = touch2.position;
        }
        /// <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 = (Recognizer as TwoFingerDragGestureRecognizer).SlopInches;

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

            TwoFingerDragGestureRecognizer recognizer =
                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.AngleThresholdRadians))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Action to be performed when this gesture is started.
        /// </summary>
        protected internal override void OnStart()
        {
            RaycastHit hit;

            if (GestureTouchesUtility.RaycastFromCamera(StartPosition, out hit))
            {
                var gameObject = hit.transform.gameObject;
                if (gameObject != null)
                {
                    TargetObject = gameObject.GetComponentInParent <Manipulator>().gameObject;
                }
            }
        }
        /// <summary>
        /// Continues the scaling of the object.
        /// </summary>
        /// <param name="gesture">The current gesture.</param>
        protected override void OnContinueManipulation(PinchGesture gesture)
        {
            m_CurrentScaleRatio += k_Sensitivity * GestureTouchesUtility.PixelsToInches(gesture.GapDelta);

            float currentScale = m_CurrentScale;

            transform.localScale = new Vector3(currentScale, currentScale, currentScale);

            // If we've tried to scale too far beyond the limit, then cancel the gesture
            // to snap back within the scale range.
            if (m_CurrentScaleRatio < -k_ElasticRatioLimit ||
                m_CurrentScaleRatio > (1.0f + k_ElasticRatioLimit))
            {
                gesture.Cancel();
            }
        }
Exemple #13
0
        /// <summary>
        /// Updates this gesture.
        /// </summary>
        /// <returns>True if the update was successful.</returns>
        protected internal override bool UpdateGesture()
        {
            Touch touch1, touch2;
            bool  foundTouches = GestureTouchesUtility.TryFindTouch(FingerId1, out touch1);

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

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

            if (touch1.phase == TouchPhase.Canceled || touch2.phase == TouchPhase.Canceled)
            {
                Cancel();
                return(false);
            }

            if (touch1.phase == TouchPhase.Ended || touch2.phase == TouchPhase.Ended)
            {
                Complete();
                return(false);
            }

            if (touch1.phase == TouchPhase.Moved || touch2.phase == TouchPhase.Moved)
            {
                float rotation = CalculateDeltaRotation(
                    touch1.position,
                    touch2.position,
                    m_PreviousPosition1,
                    m_PreviousPosition2);

                DeltaRotation       = rotation;
                m_PreviousPosition1 = touch1.position;
                m_PreviousPosition2 = touch2.position;
                return(true);
            }

            m_PreviousPosition1 = touch1.position;
            m_PreviousPosition2 = touch2.position;
            DeltaRotation       = 0.0f;
            return(false);
        }
Exemple #14
0
        /// <summary>
        /// Action to be performed when this gesture is started.
        /// </summary>
        protected internal override void OnStart()
        {
            GestureTouchesUtility.LockFingerId(FingerId);

            RaycastHit hit;

            if (GestureTouchesUtility.RaycastFromCamera(StartPosition, out hit))
            {
                var gameObject = hit.transform.gameObject;
                if (gameObject != null)
                {
                    TargetObject = gameObject.GetComponentInParent <Manipulator>().gameObject;
                }
            }

            Touch touch;

            GestureTouchesUtility.TryFindTouch(FingerId, out touch);
            Position = touch.position;
        }
Exemple #15
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 (Input.touches.Length > 1)
            {
                for (int i = 0; i < Input.touches.Length; i++)
                {
                    Touch currentTouch = Input.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);
        }
Exemple #16
0
 /// <summary>
 /// Action to be performed when this gesture is finished.
 /// </summary>
 protected internal override void OnFinish()
 {
     GestureTouchesUtility.ReleaseFingerId(FingerId);
 }
 /// <summary>
 /// Action to be performed when this gesture is started.
 /// </summary>
 protected internal override void OnStart()
 {
     GestureTouchesUtility.LockFingerId(FingerId1);
     GestureTouchesUtility.LockFingerId(FingerId2);
 }