protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = Use.GetFingers(); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers); // Store var oldPosition = transform.localPosition; if (pinchRatio != 1.0f) { // Modify the zoom value Zoom *= pinchRatio; if (Relative == true) { var screenPoint = default(Vector2); if (LeanGesture.TryGetScreenCenter(fingers, ref screenPoint) == true) { var worldPoint = ScreenDepth.Convert(screenPoint); transform.position = worldPoint + (transform.position - worldPoint) * pinchRatio; // Increment remainingTranslation += transform.localPosition - oldPosition; } } } if (Clamp == true) { Zoom = Mathf.Clamp(Zoom, ClampMin, ClampMax); } // Get t value var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime); // Lerp the current value to the target one currentZoom = Mathf.Lerp(currentZoom, Zoom, factor); // Set the new zoom SetZoom(currentZoom); if (IgnoreZ == true) { remainingTranslation.z = 0.0f; } // Dampen remainingDelta var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor); // Shift this transform by the change in delta transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation; // Update remainingDelta with the dampened value remainingTranslation = newRemainingTranslation; }
protected virtual void Update() { // Get the fingers we want to use var fingers = Use.GetFingers(); // Calculate the rotation values based on these fingers var twistDegrees = -LeanGesture.GetTwistDegrees(fingers); // Store var oldPosition = transform.localPosition; var oldRotation = transform.localRotation; // Rotate if (Relative == true) { var screenPoint = default(Vector2); if (LeanGesture.TryGetScreenCenter(fingers, ref screenPoint) == true) { var worldPoint = ScreenDepth.Convert(screenPoint); transform.RotateAround(worldPoint, transform.forward, twistDegrees); } } else { transform.Rotate(transform.forward, twistDegrees); } // Increment remainingTranslation += transform.localPosition - oldPosition; remainingRotation *= Quaternion.Inverse(oldRotation) * transform.localRotation; // Get t value var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime); // Dampen remainingDelta var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor); var newRemainingRotation = Quaternion.Slerp(remainingRotation, Quaternion.identity, factor); // Shift this transform by the change in delta transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation; transform.localRotation = oldRotation * Quaternion.Inverse(newRemainingRotation) * remainingRotation; // Update remainingDelta with the dampened value remainingTranslation = newRemainingTranslation; remainingRotation = newRemainingRotation; }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = Use.GetFingers(); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers); // Store var oldPosition = transform.localPosition; // Make sure the zoom value is valid zoom = TryClamp(zoom); if (pinchRatio != 1.0f) { // Store old zoom value and then modify zoom var oldZoom = zoom; zoom = TryClamp(zoom * pinchRatio); // Zoom relative to a point on screen? if (Relative == true) { var screenPoint = default(Vector2); if (LeanGesture.TryGetScreenCenter(fingers, ref screenPoint) == true) { // Derive actual pinchRatio from the zoom delta (it may differ with clamping) pinchRatio = zoom / oldZoom; var worldPoint = ScreenDepth.Convert(screenPoint); transform.position = worldPoint + (transform.position - worldPoint) * pinchRatio; // Increment remainingTranslation += transform.localPosition - oldPosition; if (IgnoreZ == true) { remainingTranslation.z = 0.0f; } } } } // Get t value var factor = LeanHelper.GetDampenFactor(Damping, Time.deltaTime); // Lerp the current value to the target one currentZoom = Mathf.Lerp(currentZoom, zoom, factor); // Set the new zoom SetZoom(currentZoom); // Dampen remainingDelta var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor); // Shift this transform by the change in delta transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation; // Update remainingDelta with the dampened value remainingTranslation = newRemainingTranslation; }