Ejemplo n.º 1
0
        public static IEnumerator Move(Transform transform, Vector3 newValue, float smooth, System.Action <TriTween> tweener)
        {
            TriTween tween = new TriTween()
            {
                smooth = smooth
            };

            tweener.Invoke(tween);
            yield return(null);

            Vector3 origPos  = transform.position;
            float   progress = 0;

            if (smooth != tween.smooth)
            {
                smooth = tween.smooth;
            }

            while (transform.position.ToString(stopPrecision) != newValue.ToString(stopPrecision) && progress < 1)
            {
                if (tween.isDurationBased)
                {
                    transform.position = Vector3.Lerp(origPos, newValue, progress);
                    progress          += Time.fixedUnscaledDeltaTime * 1 / smooth;
                }
                else
                {
                    transform.position = Vector3.Lerp(transform.position, newValue, smooth);
                }
                yield return(new WaitForSecondsRealtime(Time.fixedUnscaledDeltaTime));
            }
            transform.position = newValue;
        }
Ejemplo n.º 2
0
        public static IEnumerator LookAtTransform(Transform transform, Transform lookAtTransform, float smooth, System.Action <TriTween> tweener)
        {
            //Recover eventual Settings from extensions
            TriTween tween = new TriTween()
            {
                smooth = smooth
            };

            tweener.Invoke(tween);
            yield return(null);

            float      progress = 0;
            Quaternion origRot  = transform.rotation;

            if (smooth != tween.smooth)
            {
                smooth = tween.smooth;
            }

            while (transform.rotation.ToString(stopPrecision) != Quaternion.LookRotation(lookAtTransform.position - transform.position, Vector3.up).ToString(stopPrecision) && progress < 1)
            {
                if (tween.isDurationBased)
                {
                    transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(lookAtTransform.position - transform.position, Vector3.up), progress);
                    progress          += Time.fixedUnscaledDeltaTime * 1 / smooth;
                }
                else
                {
                    transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(lookAtTransform.position - transform.position, Vector3.up), smooth);
                }

                yield return(new WaitForSecondsRealtime(Time.fixedUnscaledDeltaTime));
            }
            transform.rotation = Quaternion.LookRotation(lookAtTransform.position - transform.position, Vector3.up);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tween a "Look At" to a world position in Vector 3.
        /// </summary>
        /// <param name="transform">The transform that will look at.</param>
        /// <param name="lookAtPosition">The world position toward which the designated transform will look at.</param>
        /// <param name="smooth">A linear interpolation parameter. The closer to 0, the smaller the steps will be.</param>
        /// <returns></returns>
        public static TriTween TritLookAt(this Transform transform, Vector3 lookAtPosition, float smooth = .1f)
        {
            TriTween tween = new TriTween();

            tritMonoInstance.StartCoroutine(CoTrT.LookAtVector3(transform, lookAtPosition, smooth, value => tween = value));
            return(tween);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Tween a Rotation to the orientation.
        /// </summary>
        /// <param name="transform">The transform that will rotate.</param>
        /// <param name="orientation">The rotation in euler angles which the transform will tween to</param>
        /// <param name="smooth">A linear interpolation parameter. The closer to 0, the smaller the steps will be.</param>
        public static TriTween TritRotate(this Transform transform, Vector3 orientation, float smooth = .1f)
        {
            TriTween tween = new TriTween();

            tritMonoInstance.StartCoroutine(CoTrT.Rotate(transform, orientation, smooth, value => tween = value));
            return(tween);
        }
Ejemplo n.º 5
0
        public static TriTween TritMoveEase(this Transform transform, Vector3 newValue, float smooth = .1f)
        {
            TriTween tween = new TriTween();

            tritMonoInstance.StartCoroutine(CoTrT.MoveEase(transform, newValue, smooth, value => tween = value));
            return(tween);
        }
Ejemplo n.º 6
0
        public static IEnumerator MoveEase(Transform transform, Vector3 newValue, float smooth, System.Action <TriTween> tweener)
        {
            TriTween tween = new TriTween()
            {
                smooth = smooth
            };

            tweener.Invoke(tween);
            yield return(null);

            Vector3 origPos = transform.position;
            Vector3 newPos  = Vector3.zero;
            float   t       = 0;

            tween.progress = 0;

            if (smooth != tween.smooth)
            {
                smooth = tween.smooth;
            }

            while (tween.progress < 1)
            {
                if (tween.isDurationBased && !tween.pause)
                {
                    if (smooth == 0)
                    {
                        break;
                    }

                    tween.progress = t / smooth;
                    newPos.x       = Easing.Ease(tween.easeType, origPos.x, newValue.x, tween.progress, tween.curve);
                    newPos.y       = Easing.Ease(tween.easeType, origPos.y, newValue.y, tween.progress, tween.curve);
                    newPos.z       = Easing.Ease(tween.easeType, origPos.z, newValue.z, tween.progress, tween.curve);

                    transform.position = newPos;

                    if (t == smooth)
                    {
                        break;
                    }

                    t += Time.fixedDeltaTime;

                    if (t > smooth)
                    {
                        t = smooth;
                    }
                }
                yield return(null);
            }
            transform.position = newValue;
        }