Exemplo n.º 1
0
        protected virtual void UpdateFingers(List <LeanFinger> fingers)
        {
            if (fingers.Count > 0)
            {
                // Get delta
                var delta = LeanGesture.GetScreenDelta(fingers);

                // Ignore?
                if (delta.sqrMagnitude == 0.0f)
                {
                    return;
                }

                // Scale?
                if (DeltaCoordinates == DeltaCoordinatesType.Scaled)
                {
                    delta *= LeanTouch.ScalingFactor;
                }

                // Call events
                if (OnSetCenter != null)
                {
                    OnSetCenter.Invoke(LeanGesture.GetScreenCenter(fingers));
                }

                if (OnSetDelta != null)
                {
                    OnSetDelta.Invoke(delta);
                }
            }
        }
Exemplo n.º 2
0
        private void HandleFingerUp(LeanFinger finger)
        {
            if (fingers.Remove(finger) == true)
            {
                if (fingers.Count + 1 == RequiredCount)
                {
                    if (onFingers != null)
                    {
                        onFingers.Invoke(fingers);
                    }

                    var screenPosition = LeanGesture.GetScreenCenter(fingers);

                    if (onWorld != null)
                    {
                        var worldPosition = ScreenDepth.Convert(screenPosition, gameObject);

                        onWorld.Invoke(worldPosition);
                    }

                    if (onScreen != null)
                    {
                        onScreen.Invoke(screenPosition);
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                // Get delta
                var delta = LeanGesture.GetScreenDelta(fingers);

                // Ignore?
                if (delta.sqrMagnitude == 0.0f)
                {
                    return;
                }

                // Scale?
                if (DeltaCoordinates == DeltaCoordinatesType.Scaled)
                {
                    delta *= LeanTouch.ScalingFactor;
                }

                // Call events
                if (OnSetCenter != null)
                {
                    OnSetCenter.Invoke(LeanGesture.GetScreenCenter(fingers));
                }

                if (OnSetDelta != null)
                {
                    OnSetDelta.Invoke(delta);
                }
            }
        }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        protected virtual void Update()
        {
            // Make sure the camera exists
            var camera = LeanTouch.GetCamera(Camera, gameObject);

            if (camera != null)
            {
                // Get the fingers we want to use
                var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

                if (fingers.Count > 0)
                {
                    var screenPoint   = LeanGesture.GetScreenCenter(fingers);
                    var worldPosition = default(Vector3);

                    if (ScreenDepth.TryConvert(ref worldPosition, screenPoint, camera, gameObject) == true)
                    {
                        transform.position = worldPosition;
                    }
                }
            }
            else
            {
                Debug.LogError("Failed to find camera. Either tag your cameras MainCamera, or set one in this component.", this);
            }
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = Use.GetFingers();

            if (fingers.Count > 0)
            {
                var screenFrom = LeanGesture.GetStartScreenCenter(fingers);
                var screenTo   = LeanGesture.GetScreenCenter(fingers);
                var finalDelta = screenTo - screenFrom;
                var timeScale  = 1.0f;

                if (ScaleByTime == true)
                {
                    timeScale = Time.deltaTime;
                }

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

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

                finalDelta *= Multiplier;

                if (onVector != null)
                {
                    onVector.Invoke(finalDelta * timeScale);
                }

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

                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) * timeScale);
                }

                if (onWorldFromTo != null)
                {
                    onWorldFromTo.Invoke(worldFrom, worldTo);
                }
            }
        }
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingersOrClear(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers, WheelSensitivity);

            pinch = pinchScale;

            if (pinchScale > 0.0f)
            {
                // Perform the translation if this is a relative scale
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                // Perform the scaling
                Scale(transform.localScale * pinchScale);
                Debug.Log("Pinch scale:" + pinchScale);
            }
        }
Exemplo n.º 9
0
        protected virtual void Update()
        {
            // pega os dedos que queremos usar
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // calcula pinchScale e verifique se ela é válida
            var pinchScale = LeanGesture.GetPinchScale(fingers, WheelSensitivity);

            if (pinchScale != 1.0f)
            {
                // realiza a translacao se esta for uma escala relativa
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                // realiza o dimensionamento
                Scale(transform.localScale * pinchScale);
            }
        }
Exemplo n.º 10
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingersOrClear(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calculate the rotation values based on these fingers
            var twistDegrees = LeanGesture.GetTwistDegrees(fingers);

            if (Relative == true)
            {
                var twistScreenCenter = LeanGesture.GetScreenCenter(fingers);

                if (transform is RectTransform)
                {
                    TranslateUI(twistDegrees, twistScreenCenter);
                    RotateUI(twistDegrees);
                }
                else
                {
                    Translate(twistDegrees, twistScreenCenter);
                    Rotate(twistDegrees);
                }
            }
            else
            {
                Rotate(twistDegrees);
            }
        }
Exemplo n.º 11
0
        /// <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));
        }
Exemplo n.º 12
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel scaling
//			if (RequiredSelectable != null && RequiredSelectable.IsSelected == false && !ModelManager._instance)
//			{
//				return;
//			}
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            if (fingers != null)
            {
                if (fingers.Count >= 2)
                {
                    float dis = Vector2.Distance(fingers [0].ScreenPosition, fingers [1].ScreenPosition);
                    //Debug.Log ("-----distance :" + dis);
                    if (dis < 300)
                    {
                        return;
                    }
                }
            }
            // Calculate the scaling values based on these fingers
            var scale        = LeanGesture.GetPinchScale(fingers, WheelSensitivity);
            var screenCenter = LeanGesture.GetScreenCenter(fingers);

            // Perform the scaling
            Scale(scale, screenCenter);
        }
Exemplo n.º 13
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel scaling
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Calculate the scaling values based on these fingers
            var pinchScale   = LeanGesture.GetPinchScale(fingers, WheelSensitivity);
            var screenCenter = LeanGesture.GetScreenCenter(fingers);

            int layerMask = ~LayerMask.GetMask("Ignore Raycast");

            if (Input.GetMouseButton(0))
            {
                Ray        raycast = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit raycastHit;
                if (Physics.Raycast(raycast, out raycastHit, Mathf.Infinity, layerMask, QueryTriggerInteraction.UseGlobal))
                {
                    Debug.Log("Ray hit occurred!");
                    // Perform the scaling
                    Scale(pinchScale, screenCenter, raycastHit);
                }
            }
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
0
        protected virtual void Update()
        {
            // Получить пальцы, которые мы хотим использовать
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Рассчитайтываем масштаб щепотки и убедитесь, что он действителен
            var pinchScale = LeanGesture.GetPinchScale(fingers, WheelSensitivity);

            if (pinchScale != 1.0f)
            {
                // Выполните перевод, если это относительная шкала
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                // Выполнить масштабирование
                Scale(transform.localScale * pinchScale);
            }
        }
Exemplo n.º 16
0
        protected virtual void FixedUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                var oldPosition = transform.position;
                var targetPoint = LeanGesture.GetScreenCenter(fingers);
                var newPosition = ScreenDepth.Convert(targetPoint, Camera, gameObject);
                var direction   = newPosition - oldPosition;
                var velocity    = direction / Time.fixedDeltaTime;

                // Apply the velocity
                velocity *= LeanTouch.GetDampenFactor(Dampening, Time.fixedDeltaTime);

                cachedRigidbody.velocity = velocity;

                /*
                 *              if (Rotation == true && direction != Vector3.zero)
                 *              {
                 *                      var angle           = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
                 *                      var directionB      = (Vector2)transform.up;
                 *                      var angleB          = Mathf.Atan2(directionB.x, directionB.y) * Mathf.Rad2Deg;
                 *                      var delta           = Mathf.DeltaAngle(angle, angleB);
                 *                      var angularVelocity = delta / Time.fixedDeltaTime;
                 *
                 *                      angularVelocity *= LeanTouch.GetDampenFactor(RotationDampening, Time.fixedDeltaTime);
                 *
                 *                      //cachedRigidbody.angularVelocity = angularVelocity;
                 *              }
                 */
            }
        }
Exemplo n.º 17
0
        protected virtual void Update()
        {
            // Store
            var oldScale = transform.localPosition;

            if (_localScale.Equals(Vector3.zero))
            {
                _localScale = transform.localScale;                                   //
            }
            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers);
            var newScale   = transform.localScale * pinchScale;

            if (newScale.x > _localScale.x * MAX_SCALE || newScale.x < _localScale.x * MIN_SCALE)
            {
                pinchScale = 1f;
            }

            if (pinchScale != 1.0f)
            {
                pinchScale = Mathf.Pow(pinchScale, Sensitivity);

                // Perform the translation if this is a relative scale
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                transform.localScale *= pinchScale;

                remainingScale += transform.localPosition - oldScale;
            }

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

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

            // Shift this transform by the change in delta
            transform.localPosition = oldScale + remainingScale - newRemainingScale;

            // Update remainingDelta with the dampened value
            remainingScale = newRemainingScale;
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        protected virtual void Update()
        {
            // Store
            var oldScale = transform.localPosition;

            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers);

            if (pinchScale != 1.0f)
            {
                // Perform the translation if this is a relative scale
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                transform.localScale *= pinchScale;
                float currentScale = transform.localScale.x;
                if (currentScale > 1.0f)
                {
                    transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
                }
                else if (currentScale < 0.1f)
                {
                    transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                }

                remainingScale += transform.localPosition - oldScale;
            }

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

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

            // Shift this transform by the change in delta
            transform.localPosition = oldScale + remainingScale - newRemainingScale;

            // Update remainingDelta with the dampened value
            remainingScale = newRemainingScale;
        }
Exemplo n.º 21
0
        protected virtual void Update()
        {
            // Store
            var oldScale     = transform.localPosition;
            var initialScale = transform.localScale;
            // Get the fingers we want to use
            var fingers = Use.GetFingers();

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers);

            if (pinchScale != 1.0f)
            {
                pinchScale = Mathf.Pow(pinchScale, Sensitivity);

                // Perform the translation if this is a relative scale
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }
                Vector3 m_scale = initialScale * pinchScale;

                m_scale.x            = Mathf.Clamp(m_scale.x, m_minScale, m_maxScale);
                m_scale.y            = Mathf.Clamp(m_scale.y, m_minScale, m_maxScale);
                m_scale.z            = Mathf.Clamp(m_scale.z, m_minScale, m_maxScale);
                transform.localScale = m_scale;

                remainingScale += transform.localPosition - oldScale;
            }

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

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

            // Shift this transform by the change in delta
            transform.localPosition = oldScale + remainingScale - newRemainingScale;

            // Update remainingDelta with the dampened value
            remainingScale = newRemainingScale;
        }
Exemplo n.º 22
0
        protected virtual void FixedUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                var targetPoint = LeanGesture.GetScreenCenter(fingers);
                var newPosition = ScreenDepth.Convert(targetPoint, Camera, gameObject);
                var factor      = LeanTouch.GetDampenFactor(Dampening, Time.fixedDeltaTime);

                transform.position = Vector3.Lerp(transform.position, newPosition, factor);
            }
        }
Exemplo n.º 23
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;
        }
Exemplo n.º 24
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                var screenPoint   = LeanGesture.GetScreenCenter(fingers);
                var worldPosition = default(Vector3);

                if (ScreenDepth.TryConvert(ref worldPosition, screenPoint, gameObject) == true)
                {
                    transform.position = worldPosition;
                }
            }
        }
Exemplo n.º 25
0
        protected virtual void Update()
        {
            if (Camera.main == null)
            {
                return;
            }

            // Get the fingers we want to use
            var fingers =
                LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers, WheelSensitivity);

            var newScale = transform.localScale * pinchScale;

            if (newScale.x < ScaleMin.x || newScale.x > ScaleMax.x)
            {
                return;
            }

            if (pinchScale > 0.0f)
            {
                // Perform the translation if this is a relative scale
                if (Relative == true)
                {
                    var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                    if (!Physics.Raycast(Camera.main.ScreenPointToRay(pinchScreenCenter)))
                    {
                        return;
                    }

                    if (transform is RectTransform)
                    {
                        TranslateUI(pinchScale, pinchScreenCenter);
                    }
                    else
                    {
                        Translate(pinchScale, pinchScreenCenter);
                    }
                }

                // Perform the scaling
                Scale(transform.localScale * pinchScale);
            }
        }
Exemplo n.º 26
0
        protected virtual void Update()
        {
            // Get an initial list of fingers
            var fingers = Use.GetFingers();

            // Remove fingers that didn't begin on this UI element
            for (var i = fingers.Count - 1; i >= 0; i--)
            {
                var finger = fingers[i];

                if (downFingers.Contains(finger) == false)
                {
                    fingers.RemoveAt(i);
                }
            }

            // Remove fingers that currently aren't on this UI element?
            if (IgnoreIfOff == true)
            {
                for (var i = fingers.Count - 1; i >= 0; i--)
                {
                    var finger = fingers[i];

                    if (ElementOverlapped(finger) == false)
                    {
                        fingers.RemoveAt(i);
                    }
                }
            }

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

                if (onWorld != null)
                {
                    var center   = LeanGesture.GetScreenCenter(fingers);
                    var position = ScreenDepth.Convert(center, gameObject);

                    onWorld.Invoke(position);
                }
            }
        }
Exemplo n.º 27
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel scaling
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Calculate the scaling values based on these fingers
            var scale        = LeanGesture.GetPinchScale(fingers);
            var screenCenter = LeanGesture.GetScreenCenter(fingers);

            // Perform the scaling
            Scale(scale, screenCenter);
        }
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel rotation
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, IgnoreGuiFinger, RequiredFingerCount);

            // Calculate the rotation values based on these fingers
            var center  = LeanGesture.GetScreenCenter(fingers);
            var degrees = LeanGesture.GetTwistDegrees(fingers);

            // Perform the rotation
            Rotate(center, degrees);
        }
Exemplo n.º 29
0
        protected virtual void FixedUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                var camera = LeanTouch.GetCamera(Camera, gameObject);

                if (camera != null)
                {
                    var oldPosition = transform.position;
                    var screenPoint = camera.WorldToScreenPoint(oldPosition);
                    var targetPoint = LeanGesture.GetScreenCenter(fingers);
                    var newPosition = camera.ScreenToWorldPoint(new Vector3(targetPoint.x, targetPoint.y, screenPoint.z));
                    var direction   = (Vector2)(newPosition - oldPosition);
                    var velocity    = direction / Time.fixedDeltaTime;

                    // Apply the velocity
                    velocity *= LeanTouch.GetDampenFactor(Dampening, Time.fixedDeltaTime);

                    cachedRigidbody.velocity = velocity;

                    if (Rotation == true && direction != Vector2.zero)
                    {
                        var angle           = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
                        var directionB      = (Vector2)transform.up;
                        var angleB          = Mathf.Atan2(directionB.x, directionB.y) * Mathf.Rad2Deg;
                        var delta           = Mathf.DeltaAngle(angle, angleB);
                        var angularVelocity = delta / Time.fixedDeltaTime;

                        angularVelocity *= LeanTouch.GetDampenFactor(RotationDampening, Time.fixedDeltaTime);

                        cachedRigidbody.angularVelocity = angularVelocity;
                    }
                }
                else
                {
                    Debug.LogError("Failed to find camera. Either tag your cameras MainCamera, or set one in this component.", this);
                }
            }
        }
Exemplo n.º 30
0
        // Update is called once per frame
        void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount,
                                                    RequiredSelectable);

            // Calculate pinch scale, and make sure it's valid
            var pinchScale = LeanGesture.GetPinchScale(fingers, 0);

            if (pinchScale > 0.0f)
            {
                var pinchScreenCenter = LeanGesture.GetScreenCenter(fingers);

                Translate(pinchScale, pinchScreenCenter);
            }


            // Perform the scaling
            Scale(transform.localScale * pinchScale);
        }