Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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, RequiredFingerCount);

            // Calculate the rotation values based on these fingers
            var center  = LeanGesture.GetScreenCenter(fingers);
            var degrees = LeanGesture.GetTwistDegrees(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 rotation
                    Rotate(center, degrees, raycastHit);
                }
            }
        }
Esempio n. 3
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = Use.GetFingers();

            if (fingers.Count > 0)
            {
                // Get twist
                var degrees = 0.0f;

                if (fingers.Count > 1)
                {
                    degrees = LeanGesture.GetTwistDegrees(fingers);
                }
                else if (OneFinger != OneFingerType.None)
                {
                    var firstFinger    = fingers[0];
                    var referencePoint = OneFinger == OneFingerType.FingerStart ? firstFinger.StartScreenPosition : new Vector2(Screen.width * 0.5f, Screen.height * 0.5f);

                    degrees += firstFinger.GetDeltaDegrees(referencePoint, referencePoint);
                }

                // Ignore?
                if (IgnoreIfStatic == true && degrees == 0.0f)
                {
                    return;
                }

                // Call events
                if (onTwistDegrees != null)
                {
                    onTwistDegrees.Invoke(degrees);
                }
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
 public void OnGesture(List <LeanFinger> fingers)
 {
     Debug.Log("Gesture with " + fingers.Count + " finger(s)");
     Debug.Log("    pinch scale: " + LeanGesture.GetPinchScale(fingers));
     Debug.Log("    twist degrees: " + LeanGesture.GetTwistDegrees(fingers));
     Debug.Log("    twist radians: " + LeanGesture.GetTwistRadians(fingers));
     Debug.Log("    screen delta: " + LeanGesture.GetScreenDelta(fingers));
 }
Esempio n. 6
0
        protected virtual void LateUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount);

            // Get the degrees these fingers twisted
            var degrees = LeanGesture.GetTwistDegrees(fingers);

            // Apply twist
            transform.Rotate(Vector3.forward, -degrees, Space.Self);
        }
        protected virtual void Update()
        {
            // pega os dedos que queremos usar
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            // Calcula os valores de rotação baseados nesses dedos
            var twistDegrees = LeanGesture.GetTwistDegrees(fingers);

            // Realiza rotação
            transform.Rotate(Axis, twistDegrees, Space);
        }
        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);

            // Perform rotation
            transform.Rotate(Axis, twistDegrees, Space);
        }
Esempio n. 9
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);

            // Perform rotation
            transform.Rotate(Axis, twistDegrees, Space);
        }
Esempio n. 10
0
        // Update is Called Every Frame
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Calculate the screenDelta value based on these fingers
            var screenDelta = LeanGesture.GetScreenDelta(fingers);
            var degrees     = LeanGesture.GetTwistDegrees(fingers);

            // Perform the translation
            Rotate(screenDelta, degrees);
        }
        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);
            }
        }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, cancel turn
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

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

            // The twist angle based on these fingers
            var twist = LeanGesture.GetTwistDegrees(fingers) * TwistSensitivity;

            // Rotate around axis
            transform.Rotate(TwistAxis, twist, Space);
        }
        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);
        }
Esempio n. 15
0
        protected virtual void Update()
        {
            // Get the fingers we want to use
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

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

            // Perform rotation
            //transform.Rotate(Axis, twistDegrees, Space);
            if (GameObject.FindGameObjectsWithTag("Polygon").Length != 0)
            {
                GameObject[] polygon;
                polygon = GameObject.FindGameObjectsWithTag("Polygon");
                foreach (GameObject goPoly in polygon)
                {
                    goPoly.GetComponent <MeshRenderer>().material.SetFloat("_Rotation", twistDegrees);
                }
            }
        }
Esempio n. 16
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = Use.GetFingers();

            if (fingers.Count > 0)
            {
                // Get twist
                var degrees = LeanGesture.GetTwistDegrees(fingers);

                // Ignore?
                if (IgnoreIfStatic == true && degrees == 0.0f)
                {
                    return;
                }

                // Call events
                if (onTwistDegrees != null)
                {
                    onTwistDegrees.Invoke(degrees);
                }
            }
        }
Esempio n. 17
0
        protected virtual void Update()
        {
            // Get fingers
            var fingers = LeanSelectable.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount, RequiredSelectable);

            if (fingers.Count > 0)
            {
                // Get twist
                var twist = Angle == AngleType.Degrees ? LeanGesture.GetTwistDegrees(fingers) : LeanGesture.GetTwistRadians(fingers);

                // Ignore?
                if (IgnoreIfStatic == true && twist == 0.0f)
                {
                    return;
                }

                // Call events
                if (OnTwist != null)
                {
                    OnTwist.Invoke(twist);
                }
            }
        }
Esempio n. 18
0
        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, RequiredFingerCount);
            // Calculate the rotation values based on these fingers

            var degrees = LeanGesture.GetTwistDegrees(fingers);

            var center = LeanGesture.GetScreenCenter(fingers);

//			if (fingers.Count > 0) {
//				float x = fingers [0].ScreenPosition.x - fingers [0].StartScreenPosition.x;
//				float y = fingers [0].ScreenPosition.y - fingers [0].StartScreenPosition.y;
//				Debug.Log ("y--------:" + y);
//				Debug.Log ("x--------:" + x);
//				if (y < 0)
//					y = -y;
//				if (x < 0)
//					x = -x;
//				if (x > y) {
//					Debug.Log ("---left right");
//					RotateAxis = new Vector3 (0, -10, 0);
//				} else {
//					Debug.Log ("---up down");
//					RotateAxis = new Vector3 (-10, 0, 0);
//
//				}
//			}
            //Perform the rotation
            Rotate(center, degrees);
        }
        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 = 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;
        }