Example #1
0
        /// <summary>
        /// Lerp the color of a UI element over time.
        /// </summary>
        /// <param name="targetGraphic">The target UI element to effect.</param>
        /// <param name="color">The new color to lerp to.</param>
        /// <param name="time">The amount of time to lerp over.</param>
        /// <param name="tScale">The method used to evaluate T as the lerp occurs. Defaults to linear.</param>
        /// <param name="callback">Function to call when this lerp has completed.</param>
        /// <returns></returns>
        public static IEnumerator LerpUIColor(
            Graphic targetGraphic, Color color, float time, PercentageEvaluator tScale = null,
            CallOnComplete callback = null)
        {
            if (tScale == null)
            {
                tScale = LINEAR_EVALUATOR;
            }

            float elapsedTime = 0.0f;
            Color startingVal = targetGraphic.color;

            while (elapsedTime < time)
            {
                yield return(null);

                targetGraphic.color = Color.Lerp(startingVal, color, tScale(elapsedTime, time));
                elapsedTime        += Time.deltaTime;
            }

            targetGraphic.color = color;

            if (callback != null)
            {
                callback();
            }
        }
Example #2
0
        /// <summary>
        /// Lerps the intensity of a light over the amount of time provided.
        /// </summary>
        /// <param name="light">The light to lerp.</param>
        /// <param name="newIntensity">The new target intensity value.</param>
        /// <param name="time">The amount of time to lerp over.</param>
        /// <param name="tScale">The method used to evaluate T as the lerp occurs. Defaults to linear.</param>
        /// <param name="callback">Function to call when this lerp has completed.</param>
        public static IEnumerator LerpLightIntensity(
            Light light, float newIntensity, float time, PercentageEvaluator tScale = null, CallOnComplete callback = null)
        {
            if (tScale == null)
            {
                tScale = LINEAR_EVALUATOR;
            }

            float elapsedTime = 0.0f, startingVal = light.intensity;

            while (elapsedTime < time)
            {
                light.intensity = Mathf.Lerp(startingVal, newIntensity, tScale(elapsedTime, time));

                elapsedTime += Time.deltaTime;
                yield return(null);
            }

            light.intensity = newIntensity;

            if (callback != null)
            {
                callback();
            }
        }
Example #3
0
        /// <summary>
        /// Private function for lerping a world position.
        /// </summary>
        private static IEnumerator LerpWorldPos(Transform obj, Vector3 p, float t, PercentageEvaluator tScale)
        {
            float   currentTime = 0.0f;
            Vector3 startPos    = obj.position;

            while (currentTime < t)
            {
                obj.transform.position = Vector3.Lerp(startPos, p, tScale(currentTime, t));

                currentTime += Time.deltaTime;
                yield return(null);
            }

            obj.transform.position = p;
        }
Example #4
0
        /// <summary>
        /// Generic coroutine to scale the rotation of an object in 3D.
        /// </summary>
        /// <param name="tRef">The transform to move.</param>
        /// <param name="target">The new target position.</param>
        /// <param name="time">Time to lerp over.</param>
        /// <param name="tScale">The method used to evaluate T as the lerp occurs. Defaults to linear.</param>
        /// <param name="callback">Function to call when this lerp has completed.</param>
        public static IEnumerator LerpScale(
            Transform tRef, Vector3 target, float time, PercentageEvaluator tScale = null, CallOnComplete callback = null)
        {
            if (tScale == null)
            {
                tScale = LINEAR_EVALUATOR;
            }

            yield return(LerpLocalScale(tRef, target, time, tScale));

            if (callback != null)
            {
                callback();
            }
        }
Example #5
0
        /// <summary>
        /// Generic coroutine to lerp the position of an object in 3D.
        /// </summary>
        /// <param name="tRef">The transform to move.</param>
        /// <param name="target">The new target position.</param>
        /// <param name="time">Time to lerp over.</param>
        /// <param name="space">Whether to apply this transformation to the local or world position.</param>
        /// <param name="tScale">The method used to evaluate T as the lerp occurs. Defaults to linear.</param>
        /// <param name="callback">Function to call when this lerp has completed.</param>
        public static IEnumerator LerpPosition(
            Transform tRef, Vector3 target, float time, Space space = Space.Self, PercentageEvaluator tScale = null,
            CallOnComplete callback = null)
        {
            if (tScale == null)
            {
                tScale = LINEAR_EVALUATOR;
            }

            if (space == Space.Self)
            {
                yield return(LerpLocalPos(tRef, target, time, tScale));
            }
            else
            {
                yield return(LerpWorldPos(tRef, target, time, tScale));
            }

            if (callback != null)
            {
                callback();
            }
        }
Example #6
0
        /// <summary>
        /// Private fucntion for lerping a local rotation.
        /// </summary>
        private static IEnumerator LerpLocalScale(Transform obj, Vector3 scale, float t, PercentageEvaluator tScale)
        {
            float   currentTime = 0.0f;
            Vector3 startPos    = obj.localScale;

            while (currentTime < t)
            {
                obj.transform.localScale = Vector3.Lerp(startPos, scale, tScale(currentTime, t));

                currentTime += Time.deltaTime;
                yield return(null);
            }

            obj.transform.localScale = scale;
        }
Example #7
0
        /// <summary>
        /// Private function for lerping a world rotation.
        /// </summary>
        private static IEnumerator LerpWorldRot(Transform t, Quaternion rot, float time, PercentageEvaluator tScale)
        {
            float      currentTime = 0.0f;
            Quaternion startRot    = t.rotation;

            while (currentTime < time)
            {
                t.rotation = Quaternion.Slerp(startRot, rot, tScale(currentTime, time));

                currentTime += Time.deltaTime;
                yield return(new WaitForEndOfFrame());
            }

            t.rotation = rot;
        }