/// <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 (!touch1.isInProgress || !touch2.isInProgress) { Cancel(); return(false); } // Check that at least one finger is moving. if (touch1.delta.ReadValue() == Vector2.zero && touch2.delta.ReadValue() == Vector2.zero) { return(false); } var pos1 = touch1.position.ReadValue(); var diff1 = (pos1 - StartPosition1).magnitude; var pos2 = touch2.position.ReadValue(); var diff2 = (pos2 - StartPosition2).magnitude; var slopInches = (m_Recognizer as TwoFingerDragGestureRecognizer).m_SlopInches; if (GestureTouchesUtility.PixelsToInches(diff1) < slopInches || GestureTouchesUtility.PixelsToInches(diff2) < slopInches) { return(false); } var recognizer = m_Recognizer as TwoFingerDragGestureRecognizer; // Check both fingers move in the same direction. var dot = Vector3.Dot(touch1.delta.ReadValue().normalized, touch2.delta.ReadValue().normalized); return(!(dot < Mathf.Cos(recognizer.m_AngleThresholdRadians))); }
protected internal void TryCreateGestureTwoFingerGestureOnTouchBeganForTouchControls( TouchControl touch1, TouchControl touch2, Func <TouchControl, TouchControl, T> createGestureFunction) { if (m_Gestures.Count != 0) { return; } if (!touch1.isInProgress || GestureTouchesUtility.IsTouchOffScreenEdge(touch1)) { return; } if (!touch2.isInProgress || GestureTouchesUtility.IsTouchOffScreenEdge(touch2)) { return; } var gesture = createGestureFunction(touch1, touch2); gesture.onStart += OnStart; gesture.onFinished += OnFinished; m_Gestures.Add(gesture); }
/// <summary> /// Action to be performed when this gesture is started. /// </summary> protected internal override void OnStart() { if (GestureTouchesUtility.RaycastFromCamera(StartPosition1, out var hit1)) { TargetObject = hit1.transform.gameObject; } Position = (touch1.position.ReadValue() + touch2.position.ReadValue()) / 2; }
/// <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 (!touch1.isInProgress || !touch2.isInProgress) { Cancel(); return(false); } // Check that at least one finger is moving. if (touch1.delta.ReadValue() == Vector2.zero && touch2.delta.ReadValue() == Vector2.zero) { return(false); } var pinchRecognizer = m_Recognizer as PinchGestureRecognizer; Vector3 firstToSecondDirection = (startPosition1 - startPosition2).normalized; var dot1 = Vector3.Dot(touch1.delta.ReadValue().normalized, -firstToSecondDirection); var dot2 = Vector3.Dot(touch2.delta.ReadValue().normalized, firstToSecondDirection); var dotThreshold = Mathf.Cos(pinchRecognizer.m_SlopMotionDirectionDegrees * Mathf.Deg2Rad); // Check angle of motion for the first touch. if (touch1.delta.ReadValue() != Vector2.zero && Mathf.Abs(dot1) < dotThreshold) { return(false); } // Check angle of motion for the second touch. if (touch2.delta.ReadValue() != Vector2.zero && Mathf.Abs(dot2) < dotThreshold) { return(false); } var deltaPosition = (startPosition1 - startPosition2).magnitude; gap = (touch1.position.ReadValue() - touch2.position.ReadValue()).magnitude; startGap = gap; var separation = GestureTouchesUtility.PixelsToInches(Mathf.Abs(gap - deltaPosition)); return(!(separation < pinchRecognizer.m_SlopInches)); }