protected virtual void Update() { RectTransform workstationBorders = workstation.GetComponent <RectTransform>(); Rect rectWorkstation = new Rect(getLeftWorldCorner(workstationBorders).x, getLeftWorldCorner(workstationBorders).y, 300, 600); Vector2 workstationCenter = new Vector2(rectWorkstation.center.x, rectWorkstation.center.y); Rect rectEmoji = new Rect(-1810, -282, 600, 600); if (isDragging) { // Store var oldPosition = transform.localPosition; // Get the fingers we want to use var fingers = Use.GetFingers(); // Calculate the screenDelta value based on these fingers var screenDelta = LeanGesture.GetScreenDelta(fingers); if (screenDelta != Vector2.zero) { // Perform the translation if (transform is RectTransform) { TranslateUI(screenDelta); } else { Translate(screenDelta); } } // Increment remainingTranslation += transform.localPosition - oldPosition; // Get t value var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime); // Dampen remainingDelta var newRemainingTranslation = Vector3.Lerp(remainingTranslation, Vector3.zero, factor); // Shift this transform by the change in delta transform.localPosition = oldPosition + remainingTranslation - newRemainingTranslation; if (fingers.Count == 0 && Inertia > 0.0f && Dampening > 0.0f) { newRemainingTranslation = Vector3.Lerp(newRemainingTranslation, remainingTranslation, Inertia); } // Update remainingDelta with the dampened value remainingTranslation = newRemainingTranslation; } else if (rectOverlaps(rectWorkstation)) { GetComponent <LeanPinchScale>().enabled = true; GetComponent <LeanTwistRotate>().enabled = true; transform.position = workstationCenter; lastPos = workstationCenter; } else if (rectOverlaps(rectEmoji) && lastPos == workstationCenter) { GetComponent <LeanPinchScale>().enabled = false; GetComponent <LeanTwistRotate>().enabled = false; Debug.Log(lastPos); } else { GetComponent <LeanPinchScale>().enabled = false; GetComponent <LeanTwistRotate>().enabled = false; transform.position = inventoryPos; lastPos = transform.position; transform.localScale = oldScale; transform.rotation = oldRotation; } }
protected virtual void Update() { // Store var oldPosition = transform.localPosition; var oldRotation = transform.localRotation; // Get the fingers we want to use var fingers = Use.GetFingers(); // Calculate the rotation values based on these fingers var twistDegrees = LeanGesture.GetTwistDegrees(fingers); if (twistDegrees != 0.0f) { if (Relative == true) { var twistScreenCenter = LeanGesture.GetScreenCenter(fingers); if (transform is RectTransform) { TranslateUI(twistDegrees, twistScreenCenter); RotateUI(twistDegrees); } else { Translate(twistDegrees, twistScreenCenter); Rotate(twistDegrees); } } else { if (transform is RectTransform) { RotateUI(twistDegrees); } else { Rotate(twistDegrees); } } } // Increment remainingTranslation += transform.localPosition - oldPosition; remainingRotation *= Quaternion.Inverse(oldRotation) * transform.localRotation; // Get t value var factor = LeanTouch.GetDampenFactor(Dampening, 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 = LeanTouch.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; }