Example #1
0
        protected virtual void LateUpdate()
        {
            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Get the last and current screen point of all fingers
            var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers);
            var screenPoint     = LeanGesture.GetScreenCenter(fingers);

            // Get the world delta of them after conversion
            var worldDelta = ScreenDepth.ConvertDelta(lastScreenPoint, screenPoint, gameObject);

            // Store the current position
            var oldPosition = transform.localPosition;

            // Pan the camera based on the world delta
            transform.position -= new Vector3((worldDelta * Sensitivity).x, (worldDelta * Sensitivity).x * A, (worldDelta * Sensitivity).z);

            // Add to remainingDelta
            remainingDelta += transform.localPosition - oldPosition;

            // Get t value
            var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);

            // Dampen remainingDelta
            var newRemainingDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);

            // Shift this position by the change in delta
            transform.localPosition = new Vector3((oldPosition + remainingDelta - newRemainingDelta).x, (oldPosition + remainingDelta - newRemainingDelta).x * A, (oldPosition + remainingDelta - newRemainingDelta).z);

            // Update remainingDelta with the dampened value
            remainingDelta = newRemainingDelta;
        }
        /// <summary>Gets the average twist of the fingers in radians.</summary>
        public static float GetTwistRadians(List <LeanFinger> fingers)
        {
            var center     = LeanGesture.GetScreenCenter(fingers);
            var lastCenter = LeanGesture.GetLastScreenCenter(fingers);

            return(GetTwistRadians(fingers, center, lastCenter));
        }
Example #3
0
        public static float GetPinchRatio(List <LeanFinger> fingers, float wheelSensitivity = 0.0f)
        {
            var ratio      = 1.0f;
            var center     = LeanGesture.GetScreenCenter(fingers);
            var lastCenter = LeanGesture.GetLastScreenCenter(fingers);

            TryGetPinchRatio(fingers, center, lastCenter, ref ratio, wheelSensitivity);

            return(ratio);
        }
Example #4
0
        public static float GetPinchScale(List <LeanFinger> fingers, float wheelSensitivity = 0.0f)
        {
            var scale      = 1.0f;
            var center     = LeanGesture.GetScreenCenter(fingers);
            var lastCenter = LeanGesture.GetLastScreenCenter(fingers);

            TryGetPinchScale(fingers, center, lastCenter, ref scale, wheelSensitivity);

            return(scale);
        }
Example #5
0
        protected virtual void LateUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount);

            // Get the last and current screen point of all fingers
            var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers);
            var screenPoint     = LeanGesture.GetScreenCenter(fingers);

            // Get the world delta of them after conversion
            var worldDelta = ScreenDepth.ConvertDelta(lastScreenPoint, screenPoint, gameObject);

            // Pan the camera based on the world delta
            transform.position -= worldDelta * Sensitivity;
        }
        protected virtual void LateUpdate()
        {
            // Get the fingers we want to use
            var fingers = Use.UpdateAndGetFingers();

            // Get the last and current screen point of all fingers
            var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers);
            var screenPoint     = LeanGesture.GetScreenCenter(fingers);

            // Get the world delta of them after conversion
            var worldDelta = ScreenDepth.ConvertDelta(lastScreenPoint, screenPoint, gameObject);

            // Store the current position
            var oldPosition = transform.localPosition;

            // Pan the camera based on the world delta
            transform.position -= worldDelta * sensitivity;

            // Add to remainingDelta
            remainingDelta += transform.localPosition - oldPosition;

            // Get t value
            var factor = LeanHelper.GetDampenFactor(damping, Time.deltaTime);

            // Dampen remainingDelta
            var newRemainingDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);

            // Shift this position by the change in delta
            transform.localPosition = oldPosition + remainingDelta - newRemainingDelta;

            if (fingers.Count == 0 && inertia > 0.0f && damping > 0.0f)
            {
                newRemainingDelta = Vector3.Lerp(newRemainingDelta, remainingDelta, inertia);
            }

            // Update remainingDelta with the dampened value
            remainingDelta = newRemainingDelta;
        }
Example #7
0
        protected virtual void Update()
        {
            // Get an initial list of fingers
            var fingers = Use.GetFingers();

            if (fingers.Count > 0)
            {
                // Get delta
                var screenFrom = LeanGesture.GetLastScreenCenter(fingers);
                var screenTo   = LeanGesture.GetScreenCenter(fingers);
                var finalDelta = screenTo - screenFrom;

                if (IgnoreIfStatic == true && finalDelta.sqrMagnitude <= 0.0f)
                {
                    return;
                }

                if (onFingers != null)
                {
                    onFingers.Invoke(fingers);
                }

                switch (Coordinate)
                {
                case CoordinateType.ScaledPixels:     finalDelta *= LeanTouch.ScalingFactor; break;

                case CoordinateType.ScreenPercentage: finalDelta *= LeanTouch.ScreenFactor;  break;
                }

                finalDelta *= Multiplier;

                if (onDelta != null)
                {
                    onDelta.Invoke(finalDelta);
                }

                if (onDistance != null)
                {
                    onDistance.Invoke(finalDelta.magnitude);
                }

                var worldFrom = ScreenDepth.Convert(screenFrom, gameObject);
                var worldTo   = ScreenDepth.Convert(screenTo, gameObject);

                if (onWorldFrom != null)
                {
                    onWorldFrom.Invoke(worldFrom);
                }

                if (onWorldTo != null)
                {
                    onWorldTo.Invoke(worldTo);
                }

                if (onWorldDelta != null)
                {
                    onWorldDelta.Invoke(worldTo - worldFrom);
                }

                if (onWorldFromTo != null)
                {
                    onWorldFromTo.Invoke(worldFrom, worldTo);
                }
            }
        }
Example #8
0
        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;
                }
            }
        }
Example #9
0
        protected virtual void LateUpdate()
        {
            var tempZoom = 1500 - gameObject.GetComponent <LeanCameraZoom>().Zoom;

            if (!paused.GetComponent <Pause>().isPaused)
            {
                // Get the fingers we want to use
                var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount);

                // Get the last and current screen point of all fingers
                var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers);
                var screenPoint     = LeanGesture.GetScreenCenter(fingers);

                // Get the world delta of them after conversion
                var worldDelta = ScreenDepth.ConvertDelta(lastScreenPoint, screenPoint, Camera, gameObject);

                var oldPosition = transform.localPosition;

                if (fingers.Count == 1 && fingers[0].IsActive == true)
                {
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit rayHit;
                    if (Physics.Raycast(ray, out rayHit, Mathf.Infinity, 1 << 9))
                    {
                    }
                    else
                    {
                        if (levelSelection == true) //Clamps the camera using the Min/Max set by the user
                        {
                            transform.position = new Vector3(Mathf.Clamp(transform.position.x - (worldDelta.x * Sensitivity), minX - tempZoom, maxX + tempZoom),
                                                             Mathf.Clamp(transform.position.y - (worldDelta.y * Sensitivity), minY - tempZoom, maxY + tempZoom),
                                                             Mathf.Clamp(transform.position.z - (worldDelta.z * Sensitivity), minZ, maxZ));
                        }
                        else
                        {
                            transform.position -= worldDelta * Sensitivity;                             //Main function that moves the camera around

                            //UGLY CODE -- BOUNDS
                            if (transform.localPosition.x > maxX)
                            {
                                transform.localPosition = new Vector3(maxX, transform.localPosition.y, transform.localPosition.z);
                            }
                            if (transform.localPosition.x < minX)
                            {
                                transform.localPosition = new Vector3(minX, transform.localPosition.y, transform.localPosition.z);
                            }
                            if (transform.localPosition.y > maxY)
                            {
                                transform.localPosition = new Vector3(transform.localPosition.x, maxY, transform.localPosition.z);
                            }
                            if (transform.localPosition.y < minY)
                            {
                                transform.localPosition = new Vector3(transform.localPosition.x, minY, transform.localPosition.z);
                            }
                            if (transform.localPosition.z > maxZ)
                            {
                                transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, maxZ);
                            }
                            if (transform.localPosition.z < minZ)
                            {
                                transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, minZ);
                            }
                        }
                    }
                }
                else
                {
                    if (levelSelection == true) //Ensures zooming out affects the current position of the camera
                    {
                        transform.position = new Vector3(Mathf.Clamp(transform.localPosition.x - (worldDelta.x * Sensitivity), minX - tempZoom, maxX + tempZoom),
                                                         Mathf.Clamp(transform.localPosition.y - (worldDelta.y * Sensitivity), minY - tempZoom, maxY + tempZoom),
                                                         Mathf.Clamp(transform.localPosition.z - (worldDelta.z * Sensitivity), minZ, maxZ));

                        /*
                         *
                         * // Pan the camera based on the world delta
                         *
                         *
                         * // Add to remainingDelta
                         * remainingDelta += transform.localPosition - oldPosition;
                         *
                         * // Get t value
                         * var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime);
                         *
                         * // Dampen remainingDelta
                         * var newRemainingDelta = Vector3.Lerp(remainingDelta, Vector3.zero, factor);
                         *
                         * // Shift this position by the change in delta
                         * transform.localPosition = oldPosition + remainingDelta - newRemainingDelta;
                         *
                         * if (fingers.Count == 0 && Inertia > 0.0f && Dampening > 0.0f)
                         * {
                         *      newRemainingDelta = Vector3.Lerp(newRemainingDelta, remainingDelta, Inertia);
                         * }
                         *
                         * // Update remainingDelta with the dampened value
                         * remainingDelta = newRemainingDelta;
                         */
                    }
                }
            }
        }