TwoFingerDragGesture(TwoFingerDragGestureRecognizer recognizer, CommonTouch touch1, CommonTouch touch2) : base(recognizer) { fingerId1 = touch1.fingerId; startPosition1 = touch1.position; fingerId2 = touch2.fingerId; startPosition2 = touch2.position; position = (startPosition1 + startPosition2) / 2; }
/// <summary> /// Constructs a two finger drag gesture. /// </summary> /// <param name="recognizer">The gesture recognizer.</param> /// <param name="touch1">The first touch that started this gesture.</param> /// <param name="touch2">The second touch that started this gesture.</param> public TwoFingerDragGesture( TwoFingerDragGestureRecognizer recognizer, Touch touch1, Touch touch2) : base(recognizer) { FingerId1 = touch1.fingerId; StartPosition1 = touch1.position; FingerId2 = touch2.fingerId; StartPosition2 = touch2.position; Position = (StartPosition1 + StartPosition2) / 2; }
/// <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); }
/// <summary> /// Constructs a two finger drag gesture. /// </summary> /// <param name="recognizer">The gesture recognizer.</param> /// <param name="touch1">The first touch that started this gesture.</param> /// <param name="touch2">The second touch that started this gesture.</param> public TwoFingerDragGesture(TwoFingerDragGestureRecognizer recognizer, InputSystem.EnhancedTouch.Touch touch1, InputSystem.EnhancedTouch.Touch touch2) : this(recognizer, new CommonTouch(touch1), new CommonTouch(touch2)) { }
/// <summary> /// Constructs a two finger drag gesture. /// </summary> /// <param name="recognizer">The gesture recognizer.</param> /// <param name="touch1">The first touch that started this gesture.</param> /// <param name="touch2">The second touch that started this gesture.</param> public TwoFingerDragGesture(TwoFingerDragGestureRecognizer recognizer, Touch touch1, Touch touch2) : this(recognizer, new CommonTouch(touch1), new CommonTouch(touch2)) { }