Exemplo n.º 1
0
        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 to translate
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Get the scaled average movement vector of these fingers
            var drag = LeanGesture.GetScaledDelta(fingers);

            // Find the rotation
            var rotation = Quaternion.identity;

            if (RelativeTo != null)
            {
                rotation = RelativeTo.rotation;
            }

            // The distance we want to translate by in degrees
            var speedX = drag.x * HorizontalSensitivity;

            // Translate along axis
            transform.position += rotation * HorizontalAxis.normalized * speedX;

            // The angle we want to translate by in degrees
            var speedY = drag.y * VerticalSensitivity;

            // Translate along axis
            transform.position += rotation * VerticalAxis.normalized * speedY;
        }
Exemplo n.º 2
0
        protected virtual void Update()
        {
            // If we require a selectable and it isn't selected, skip
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

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

            // Get the scaled average movement vector of these fingers
            var drag = LeanGesture.GetScaledDelta(fingers);

            // The angle we want to rotate by in degrees
            var angleX = drag.x * HorizontalSensitivity;

            // Rotate around axis
            transform.Rotate(HorizontalAxis, angleX, Space);

            // The angle we want to rotate by in degrees
            var angleY = drag.y * VerticalSensitivity;

            // Rotate around axis
            transform.Rotate(VerticalAxis, angleY, Space);
        }
Exemplo n.º 3
0
        protected virtual void LateUpdate()
        {
            // Get the fingers we want to use
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Get the scaled average movement vector of these fingers
            var drag = LeanGesture.GetScaledDelta(fingers);

            // Get base sensitivity
            var sensitivity = GetSensitivity();

            // Adjust pitch
            Pitch += drag.y * PitchSensitivity * sensitivity;

            if (PitchClamp == true)
            {
                Pitch = Mathf.Clamp(Pitch, PitchMin, PitchMax);
            }

            // Adjust yaw
            Yaw -= drag.x * YawSensitivity * sensitivity;

            if (YawClamp == true)
            {
                Yaw = Mathf.Clamp(Yaw, YawMin, YawMax);
            }

            // Rotate to pitch and yaw values
            transform.localRotation = Quaternion.Euler(Pitch, Yaw, 0.0f);
        }
Exemplo n.º 4
0
        protected virtual void Update()
        {
            // Get the fingers we want to use to rotate
            var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount);

            // Active?
            if (fingers.Count > 0)
            {
                // Add the scaled average movement vector of these fingers
                activeScaledDelta += LeanGesture.GetScaledDelta(fingers);

                // Prevent division by zero
                if (HorizontalThreshold != 0.0f)
                {
                    var stepX = (int)(activeScaledDelta.x / HorizontalThreshold);

                    if (stepX != 0)
                    {
                        remainingRotation += HorizontalRotation * stepX;

                        activeScaledDelta.x -= stepX * HorizontalThreshold;
                    }
                }

                // Prevent division by zero
                if (VerticalThreshold != 0.0f)
                {
                    var stepY = (int)(activeScaledDelta.y / VerticalThreshold);

                    if (stepY != 0)
                    {
                        remainingRotation += VerticalRotation * stepY;

                        activeScaledDelta.y -= stepY * VerticalThreshold;
                    }
                }
            }
            // Reset
            else
            {
                activeScaledDelta.x = 0.0f;
                activeScaledDelta.y = 0.0f;
            }

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

            // Store old rotation
            var oldRotation = remainingRotation;

            // Dampen remaining
            remainingRotation = Vector3.Lerp(remainingRotation, Vector3.zero, factor);

            // Rotate by delta
            transform.Rotate(oldRotation - remainingRotation, Space);
        }
        void Update()
        {
            if (lastCount != count)
            {
                //boost the player speed!
                float boost = 500f / rb.velocity.magnitude;
                rb.AddForce(rb.velocity.normalized * boost, ForceMode.Impulse);
                lastCount = count;
            }
            resetTimeOutofCloud(checkOutOfCloud());

            // Check if game started and implement touch & keyboard input accordingly
            if (!isStarted)
            {
                if (Input.anyKey || Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    rb.AddForce(new Vector3(0.0f, 0.0f, 100f) * speed);
                    isStarted = true;
                }
            }
            else
            {
                if (Input.GetKey(KeyCode.RightArrow))
                {
                    transform.position += Vector3.right * speed * Time.deltaTime;
                }
                if (Input.GetKey(KeyCode.LeftArrow))
                {
                    transform.position += Vector3.left * speed * Time.deltaTime;
                }
                if (Input.GetKey(KeyCode.UpArrow))
                {
                    transform.position += Vector3.up * speed * Time.deltaTime;
                }
                if (Input.GetKey(KeyCode.DownArrow))
                {
                    transform.position += Vector3.down * speed * Time.deltaTime;
                }
            }

            // Touch input
            // If we require a selectable and it isn't selected, cancel translation
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                return;
            }

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

            // Calculate the scaledDelta value based on these fingers
            var scaledDelta = LeanGesture.GetScaledDelta(fingers);

            // Perform the translation
            Translate(scaledDelta);
        }
        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);
            }
        }
Exemplo n.º 7
0
        protected virtual void LateUpdate()
        {
            // If we require a selectable and it isn't selected, skip
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                UpdateRotation();

                return;
            }

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

            // Get the scaled average movement vector of these fingers
            var drag = LeanGesture.GetScaledDelta(fingers);

            // Get base sensitivity
            var sensitivity = GetSensitivity();

            // Adjust pitch
            Pitch += drag.y * PitchSensitivity * sensitivity;

            if (PitchClamp == true)
            {
                Pitch = Mathf.Clamp(Pitch, PitchMin, PitchMax);
            }

            // Adjust yaw
            Yaw -= drag.x * YawSensitivity * sensitivity;

            if (YawClamp == true)
            {
                Yaw = Mathf.Clamp(Yaw, YawMin, YawMax);
            }

            UpdateRotation();
        }
Exemplo n.º 8
0
        protected virtual void LateUpdate()
        {
            // If we require a selectable and it isn't selected, skip
            if (RequiredSelectable != null && RequiredSelectable.IsSelected == false)
            {
                UpdateRotation();

                return;
            }

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

            // Get the scaled average movement vector of these fingers
            var drag = LeanGesture.GetScaledDelta(fingers);

            // Inertia?
            if (Inertia == true && InertiaTime > 0.0f)
            {
                for (var i = fingers.Count - 1; i >= 0; i--)
                {
                    var finger = fingers[i];

                    if (finger.Up == true)
                    {
                        inertiaRemaining += finger.GetSnapshotScaledDelta(InertiaTime) / InertiaTime;
                    }
                }

                drag += inertiaRemaining * Time.deltaTime;

                // Dampen inertia
                var factor = LeanTouch.GetDampenFactor(InertiaDampening, Time.deltaTime);

                inertiaRemaining = Vector2.Lerp(inertiaRemaining, Vector2.zero, factor);
            }

            // Get base sensitivity
            var sensitivity = GetSensitivity();

            // Adjust pitch
            Pitch += drag.y * PitchSensitivity * sensitivity;

            if (PitchClamp == true)
            {
                Pitch = Mathf.Clamp(Pitch, PitchMin, PitchMax);
            }

            // Adjust yaw
            Yaw -= drag.x * YawSensitivity * sensitivity;

            if (YawClamp == true)
            {
                Yaw = Mathf.Clamp(Yaw, YawMin, YawMax);
            }

            // Auto shift yaw?
            if (AutoRotate == true)
            {
                autoRotateCooldown += Time.deltaTime;

                if (autoRotateCooldown >= AutoRotateDelay)
                {
                    autoRotateStrength += AutoRotateAcceleration * Time.deltaTime;
                }
                else
                {
                    autoRotateStrength = 0.0f;
                }

                Yaw += Mathf.Clamp01(autoRotateStrength) * AutoRotateSpeed * Time.deltaTime;
            }

            UpdateRotation();
        }