protected virtual void Update() { // Get fingers var fingers = Use.GetFingers(); // Get pinch var pinch = Coordinate == CoordinateType.OneBasedReciprocal == true?LeanGesture.GetPinchRatio(fingers) : LeanGesture.GetPinchScale(fingers); // Ignore? if (pinch == 1.0f) { return; } // This gives you a 0 based pinch value, allowing usage with translation and rotation if (Coordinate == CoordinateType.ZeroBased) { pinch -= 1.0f; pinch *= Multiplier; } else { pinch = Mathf.Pow(pinch, Multiplier); } // Call events if (onPinch != null) { onPinch.Invoke(pinch); } }
// LateUpdate Runs after Every Frame protected virtual void LateUpdate() { // If camera is null, try and get the main camera, return true if a camera was found if (LeanTouch.GetCamera(ref Camera) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Scale the current value based on the pinch ratio Target *= LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Clamp the current value to min/max values Target = Mathf.Clamp(Target, Minimum, Maximum); // The framerate independent damping factor var factor = 1.0f - Mathf.Exp(-Dampening * Time.deltaTime); // Store the current size/fov in a temp variable var current = GetCurrent(); current = Mathf.Lerp(current, Target, factor); SetCurrent(current); } }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Change the distance based on pinch gesture Distance *= LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Limit distance to min/max values? if (DistanceClamp == true) { Distance = Mathf.Clamp(Distance, DistanceMin, DistanceMax); } // Reset position transform.localPosition = Vector3.zero; // Collide against stuff? if (CollisionLayers != 0) { var hit = default(RaycastHit); var start = transform.TransformPoint(Direction.normalized * DistanceMin); var direction = transform.TransformDirection(Direction); var distanceSpread = DistanceMax - DistanceMin; if (Physics.SphereCast(start, CollisionRadius, direction, out hit, distanceSpread, CollisionLayers) == true) { Distance = DistanceMin + hit.distance; } } // Dolly back by on distance transform.Translate(Direction.normalized * Distance); }
protected virtual void Update() { // Get fingers var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable); if (fingers.Count > 0) { scale *= LeanGesture.GetPinchRatio(fingers); twist += LeanGesture.GetTwistDegrees(fingers); if (state == StateType.None) { if (Mathf.Abs(scale - 1.0f) >= PinchThreshold) { state = PinchMode; } else if (Mathf.Abs(twist) >= TwistThreshold) { state = TwistMode; } } } else { state = StateType.None; scale = 1.0f; twist = 0.0f; } switch (state) { case StateType.None: { PinchComponent.enabled = false; TwistComponent.enabled = false; } break; case StateType.Scale: { PinchComponent.enabled = true; TwistComponent.enabled = false; } break; case StateType.Rotate: { PinchComponent.enabled = false; TwistComponent.enabled = true; } break; case StateType.ScaleRotate: { PinchComponent.enabled = true; TwistComponent.enabled = true; } break; } }
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() { var camera = LeanTouch.GetCamera(Camera, gameObject); if (camera != null) { var finalTransform = Target != null ? Target.transform : transform; // Get the fingers we want to use var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); var pinchShift = pinchRatio - 1.0f; var center = LeanGesture.GetScreenCenter(fingers); if (fingers.Count == 0) { center = Input.mousePosition; } var ray = camera.ScreenPointToRay(center); finalTransform.position -= ray.direction * pinchShift * SpeedMultiplier; } }
protected virtual void Update() { // Get fingers var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable); // Get pinch var pinch = Scale == ScaleType.PinchRatio == true?LeanGesture.GetPinchRatio(fingers, WheelSensitivity) : LeanGesture.GetPinchScale(fingers, WheelSensitivity); // Ignore? if (pinch == 1.0f) { return; } // This gives you a 0 based pinch value, allowing usage with translation and rotation if (Scale == ScaleType.PinchShift) { pinch -= 1.0f; } // Call events if (OnPinch != null) { OnPinch.Invoke(pinch); } }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Perform the translation if this is a relative scale if (Relative == true) { var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers); Translate(pinchRatio, pinchScreenCenter); } // Modify the zoom value Zoom *= pinchRatio; if (ZoomClamp == true) { Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax); } // Set the new zoom SetZoom(Zoom); }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var pinch = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Dolly the camera based on the pinch ratio transform.position += Vector - Vector * pinch; }
protected virtual void Update() { // Get fingers var fingers = Use.GetFingers(); if (fingers.Count > 0) { delta += LeanGesture.GetScaledDelta(fingers); scale *= LeanGesture.GetPinchRatio(fingers); twist += LeanGesture.GetTwistDegrees(fingers); if (state == StateType.None) { if (DragComponent != null && delta.magnitude >= DragThreshold) { state = StateType.Drag; } else if (PinchComponent != null && Mathf.Abs(scale - 1.0f) >= PinchThreshold) { state = StateType.Pinch; } else if (TwistComponent != null && Mathf.Abs(twist) >= TwistThreshold) { state = StateType.Twist; } } } else { state = StateType.None; delta = Vector2.zero; scale = 1.0f; twist = 0.0f; } if (DragComponent != null) { DragComponent.enabled = state == StateType.Drag || (EnableWithoutIsolation == true && state == StateType.None); } if (PinchComponent != null) { PinchComponent.enabled = state == StateType.Pinch || (EnableWithoutIsolation == true && state == StateType.None); } if (TwistComponent != null) { TwistComponent.enabled = state == StateType.Twist || (EnableWithoutIsolation == true && state == StateType.None) || (TwistWithPinch == true && state == StateType.Pinch); } }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var pinch = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Translate the GameObject along Axis based on the pinch ratio transform.Translate(Axis * (pinch - 1.0f) * Sensitivity, Space); }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Modify the zoom value Zoom *= pinchRatio; if (ZoomClamp == true) { Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax); } // Set the new zoom SetZoom(Zoom); }
protected virtual void LateUpdate() { // Make sure the camera exists if (LeanTouch.GetCamera(ref Camera, gameObject) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers); if (fingers.Count > 1) { ChangeToolOnHand(true); } // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Modify the zoom value Zoom *= pinchRatio; Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax); // Get the world delta of all the fingers if (fingers.Count > 1) { var worldDelta = LeanGesture.GetWorldDelta(fingers, 0, Camera); // Pan the camera based on the world delta var newPos = transform.position - worldDelta * Sensitivity; if (!isSpecialBounds) { bounds = new Vector2(Camera.main.pixelWidth / 100, Camera.main.pixelHeight / 100); } newPos.x = Mathf.Clamp(newPos.x, -bounds.x, bounds.x); newPos.y = Mathf.Clamp(newPos.y, -bounds.y, bounds.y); transform.position = newPos; } // Set the new zoom SetZoom(Zoom); } }
protected virtual void LateUpdate() { // If camera is null, try and get the main camera, return true if a camera was found if (LeanTouch.GetCamera(ref Camera) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Store the current size/fov in a temp variable var current = GetCurrent(); // Scale the current value based on the pinch ratio current *= LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Clamp the current value to min/max values current = Mathf.Clamp(current, Minimum, Maximum); // Set the new size/fov SetCurrent(current); } }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var pinch = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Dolly the camera based on the pinch ratio RemainingDelta += Vector - Vector * pinch; // The framerate independent damping factor var factor = Mathf.Exp(-Dampening * Time.deltaTime); // Dampen remainingDelta var newDelta = RemainingDelta * factor; // Shift this transform by the change in delta transform.position += RemainingDelta - newDelta; // Update remainingDelta with the dampened value RemainingDelta = newDelta; }
protected virtual void LateUpdate() { // Make sure the camera exists if (LeanTouch.GetCamera(ref Camera, gameObject) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Modify the zoom value Zoom *= pinchRatio; if (ZoomClamp == true) { Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax); } // Set the new zoom SetZoom(Zoom); } }
protected virtual void LateUpdate() { // If camera is null, try and get the main camera, return true if a camera was found if (LeanTouch.GetCamera(ref Camera) == true) { // Get the world delta of all the fingers var worldDelta = LeanGesture.GetWorldDelta(Distance); // Subtract the delta to the position Camera.transform.position -= worldDelta; // Store the old FOV in a temp variable var fieldOfView = Camera.fieldOfView; // Scale the FOV based on the pinch scale fieldOfView *= LeanGesture.GetPinchRatio(); // Clamp the FOV to out min/max values fieldOfView = Mathf.Clamp(fieldOfView, FovMin, FovMax); // Set the new FOV Camera.fieldOfView = fieldOfView; } }
protected virtual void LateUpdate() { // If camera is null, try and get the main camera, return true if a camera was found if (LeanTouch.GetCamera(ref Camera) == true) { // Get the world delta of all the fingers var worldDelta = LeanGesture.GetWorldDelta(1.0f, Camera); // Distance doesn't matter with an orthographic camera // Subtract the delta to the position Camera.transform.position -= worldDelta; // Store the old size in a temp variable var orthographicSize = Camera.orthographicSize; // Scale the size based on the pinch scale orthographicSize *= LeanGesture.GetPinchRatio(); // Clamp the size to out min/max values orthographicSize = Mathf.Clamp(orthographicSize, Minimum, Maximum); // Set the new size Camera.orthographicSize = orthographicSize; } }
protected virtual void Update() { // Get fingers var fingers = Use.GetFingers(); if (fingers.Count > 1 && onPinch != null) { switch (Coordinate) { case CoordinateType.OneBasedScale: { var scale = LeanGesture.GetPinchScale(fingers); scale = Mathf.Pow(scale, Multiplier); onPinch.Invoke(scale); } break; case CoordinateType.OneBasedRatio: { var ratio = LeanGesture.GetPinchRatio(fingers); ratio = Mathf.Pow(ratio, Multiplier); onPinch.Invoke(ratio); } break; case CoordinateType.ZeroBasedScale: { var scale = LeanGesture.GetPinchScale(fingers); scale = (scale - 1.0f) * Multiplier; onPinch.Invoke(scale); } break; case CoordinateType.ZeroBasedRatio: { var ratio = LeanGesture.GetPinchRatio(fingers); ratio = (ratio - 1.0f) * Multiplier; onPinch.Invoke(ratio); } break; case CoordinateType.ZeroBasedDistance: { var oldDistance = LeanGesture.GetLastScaledDistance(fingers, LeanGesture.GetLastScreenCenter(fingers)); var newDistance = LeanGesture.GetScaledDistance(fingers, LeanGesture.GetScreenCenter(fingers)); var movement = (newDistance - oldDistance) * Multiplier; onPinch.Invoke(movement); } break; } } }
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; }