// Blend between two curves based on the value of t
    public static float CrossFade(EasingCurve curveA, EasingCurve curveB, float t)
    {
        float easedValueA = curveA.GetEasedValue(t);
        float easedValueB = curveB.GetEasedValue(t);

        return(((1 - t) * easedValueA) + (t * easedValueB));
    }
 /// <summary>
 /// Create a second-order Delegate Curve
 /// </summary>
 /// <param name="curveA">First instance of `EasingCurve`</param>
 /// <param name="curveB">Second instance of `EasingCurve`</param>
 /// <param name="curveFunc2">Second-order combination function</param>
 public DelegateCurve(EasingCurve curveA, EasingCurve curveB, Curve2 curveFunc2)
 {
     this.curveA     = curveA;
     this.curveB     = curveB;
     this.curveFunc2 = curveFunc2;
     this.order      = Order.Two;
 }
    // Use a blend of the results from two curves
    public static float Blend(EasingCurve curveA, EasingCurve curveB, float t, float blendValue)
    {
        float easedValueA = curveA.GetEasedValue(t);
        float easedValueB = curveB.GetEasedValue(t);

        return(easedValueA + (blendValue * (easedValueB - easedValueA)));
    }
예제 #4
0
        static private float EaseP(float u, EasingCurve curve, float mod)
        {
            float u2 = u;

            switch (curve)
            {
            case EasingCurve.In:
                if (float.IsNaN(mod))
                {
                    mod = 2;
                }
                u2 = Mathf.Pow(u, mod);
                break;

            case EasingCurve.Out:
                if (float.IsNaN(mod))
                {
                    mod = 2;
                }
                u2 = 1 - Mathf.Pow(1 - u, mod);
                break;

            case EasingCurve.InOut:
                if (float.IsNaN(mod))
                {
                    mod = 2;
                }
                if (u <= 0.5f)
                {
                    u2 = 0.5f * Mathf.Pow(u * 2, mod);
                }
                else
                {
                    u2 = 0.5f + 0.5f * (1 - Mathf.Pow(1 - (2 * (u - 0.5f)), mod));
                }
                break;

            case EasingCurve.Sin:
                if (float.IsNaN(mod))
                {
                    mod = 0.15f;
                }
                u2 = u + mod * Mathf.Sin(2 * Mathf.PI * u);
                break;

            case EasingCurve.SinIn:
                u2 = 1 - Mathf.Cos(u * Mathf.PI * 0.5f);
                break;

            case EasingCurve.SinOut:
                u2 = Mathf.Sin(u * Mathf.PI * 0.5f);
                break;

            case EasingCurve.Linear:
            default:
                break;
            }

            return(u2);
        }
예제 #5
0
        public Vector2 GetValue(Vector2 from, Vector2 to, float t)
        {
            Vector2 vector2 = new Vector2();

            vector2.x = EasingCurve.GetValue(this.easeType, from.x, to.x, t);
            vector2.y = EasingCurve.GetValue(this.easeType, from.y, to.y, t);
            return(vector2);
        }
예제 #6
0
        public Vector3 GetValue(Vector3 from, Vector3 to, float t)
        {
            Vector3 vector3 = new Vector3();

            vector3.x = EasingCurve.GetValue(this.easeType, from.x, to.x, t);
            vector3.y = EasingCurve.GetValue(this.easeType, from.y, to.y, t);
            vector3.z = EasingCurve.GetValue(this.easeType, from.z, to.z, t);
            return(vector3);
        }
예제 #7
0
        public Vector4 GetValue(Vector4 from, Vector4 to, float t)
        {
            Vector4 vector4 = new Vector4();

            vector4.x = EasingCurve.GetValue(this.easeType, from.x, to.x, t);
            vector4.y = EasingCurve.GetValue(this.easeType, from.y, to.y, t);
            vector4.z = EasingCurve.GetValue(this.easeType, from.z, to.z, t);
            vector4.w = EasingCurve.GetValue(this.easeType, from.w, to.w, t);
            return(vector4);
        }
예제 #8
0
        public Color GetValue(Color from, Color to, float t)
        {
            Color color = new Color();

            color.r = EasingCurve.GetValue(this.easeType, from.r, to.r, t);
            color.g = EasingCurve.GetValue(this.easeType, from.g, to.g, t);
            color.b = EasingCurve.GetValue(this.easeType, from.b, to.b, t);
            color.a = EasingCurve.GetValue(this.easeType, from.a, to.a, t);
            return(color);
        }
 /// <summary>
 /// Create a first-order Delegate Curve
 /// </summary>
 /// <param name="curve">Instance of `EasingCurve`</param>
 /// <param name="curveFunc1">First-order combination function </param>
 public DelegateCurve(EasingCurve curve, Curve1 curveFunc1)
 {
     this.curveA     = curve;
     this.curveFunc1 = curveFunc1;
     this.order      = Order.One;
 }
예제 #10
0
 static public float Ease(float u, EasingCurve curve, float mod)
 {
     return(EaseP(u, curve, mod));
 }
예제 #11
0
        static private void EaseParse(EasingCurve curveIn)
        {
            EasingCachedCurve ecc = new EasingCachedCurve();

            CASHE.Add(curveIn, ecc);
        }
    private IEnumerator AnimateWithRespectCoroutine(float fromValue, float toValue, Func <float> percentageFetcherFunction, Action <float> mutatorFunction, EasingCurve easingCurve)
    {
        float currentPercentage;

        do
        {
            currentPercentage = percentageFetcherFunction();
            float newValue = easingCurve.Apply(fromValue, toValue, currentPercentage);
            mutatorFunction(newValue);
            yield return(null);
        } while (currentPercentage + float.Epsilon < 1);
    }
    private IEnumerator AnimateOverTimeCoroutine(float fromValue, float toValue, float timeSpanSeconds, Action <float> mutatorFunction, EasingCurve easingCurve)
    {
        System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        stopwatch.Start();

        float currentPercentage;

        do
        {
            currentPercentage = (stopwatch.ElapsedMilliseconds / 1000F) / timeSpanSeconds;
            float newValue = easingCurve.Apply(fromValue, toValue, currentPercentage);
            mutatorFunction(newValue);
            yield return(null);
        } while (currentPercentage + float.Epsilon < 1);
    }
 public void Animate(float fromValue, float toValue, Func <float> percentageFetcherFunction, Action <float> mutatorFunction, EasingCurve easingCurve)
 {
     StartCoroutine(AnimateWithRespectCoroutine(fromValue, toValue, percentageFetcherFunction, mutatorFunction, easingCurve));
 }
 public void Animate(float fromValue, float toValue, float timeSpanSeconds, Action <float> mutatorFunction, EasingCurve easingCurve)
 {
     StartCoroutine(AnimateOverTimeCoroutine(fromValue, toValue, timeSpanSeconds, mutatorFunction, easingCurve));
 }
예제 #16
0
 public EasingInterpolator(EasingCurve curve)
 {
     _curve = curve;
 }
    // Utility functions for creating new curves

    // Invert the result of curve (1 - x)
    public static float Invert(EasingCurve curve, float t)
    {
        return(1 - curve.GetEasedValue(t));
    }
 // Multiple the result of one curve by another
 public static float Multiply(EasingCurve curveA, EasingCurve curveB, float t)
 {
     return(curveA.GetEasedValue(t) * curveB.GetEasedValue(t));
 }
 // Use the result of one curve as the parameter for another
 public static float Compose(EasingCurve curveA, EasingCurve curveB, float t)
 {
     return(curveA.GetEasedValue(curveB.GetEasedValue(t)));
 }
예제 #20
0
        public float GetValue(float from, float to, float t)
        {
            float value = EasingCurve.GetValue(this.easeType, from, to, t);

            return(value);
        }
예제 #21
0
 public EasingAnimation(EasingCurve curve, IInterpolator interpolator)
 {
     _curve        = curve ?? new EasingCurve();
     _interpolator = interpolator;
 }