Exemple #1
0
 public static float EaseInOut(float time, float duration, float unusedOvershootOrAmplitude, float unusedPeriod)
 {
     if (time < duration * 0.5f)
     {
         return(Bounce.EaseIn(time * 2f, duration, -1f, -1f) * 0.5f);
     }
     return(Bounce.EaseOut(time * 2f - duration, duration, -1f, -1f) * 0.5f + 0.5f);
 }
Exemple #2
0
        public static EaseFunction ToEaseFunction(Ease ease)
        {
            switch (ease)
            {
            case Ease.Linear:
                return((float time, float duration, float overshootOrAmplitude, float period) => time / duration);

            case Ease.InSine:
                return((float time, float duration, float overshootOrAmplitude, float period) => - (float)Math.Cos((double)(time / duration * 1.57079637f)) + 1f);

            case Ease.OutSine:
                return((float time, float duration, float overshootOrAmplitude, float period) => (float)Math.Sin((double)(time / duration * 1.57079637f)));

            case Ease.InOutSine:
                return((float time, float duration, float overshootOrAmplitude, float period) => - 0.5f * ((float)Math.Cos((double)(3.14159274f * time / duration)) - 1f));

            case Ease.InQuad:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time /= duration) * time);

            case Ease.OutQuad:
                return((float time, float duration, float overshootOrAmplitude, float period) => - (time /= duration) * (time - 2f));

            case Ease.InOutQuad:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if ((time /= duration * 0.5f) < 1f)
                    {
                        return 0.5f * time * time;
                    }
                    return -0.5f * ((time -= 1f) * (time - 2f) - 1f);
                });

            case Ease.InCubic:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time /= duration) * time * time);

            case Ease.OutCubic:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time = time / duration - 1f) * time * time + 1f);

            case Ease.InOutCubic:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if ((time /= duration * 0.5f) < 1f)
                    {
                        return 0.5f * time * time * time;
                    }
                    return 0.5f * ((time -= 2f) * time * time + 2f);
                });

            case Ease.InQuart:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time /= duration) * time * time * time);

            case Ease.OutQuart:
                return((float time, float duration, float overshootOrAmplitude, float period) => - ((time = time / duration - 1f) * time * time * time - 1f));

            case Ease.InOutQuart:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if ((time /= duration * 0.5f) < 1f)
                    {
                        return 0.5f * time * time * time * time;
                    }
                    return -0.5f * ((time -= 2f) * time * time * time - 2f);
                });

            case Ease.InQuint:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time /= duration) * time * time * time * time);

            case Ease.OutQuint:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time = time / duration - 1f) * time * time * time * time + 1f);

            case Ease.InOutQuint:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if ((time /= duration * 0.5f) < 1f)
                    {
                        return 0.5f * time * time * time * time * time;
                    }
                    return 0.5f * ((time -= 2f) * time * time * time * time + 2f);
                });

            case Ease.InExpo:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if (time != 0f)
                    {
                        return (float)Math.Pow(2.0, (double)(10f * (time / duration - 1f)));
                    }
                    return 0f;
                });

            case Ease.OutExpo:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if (time == duration)
                    {
                        return 1f;
                    }
                    return -(float)Math.Pow(2.0, (double)(-10f * time / duration)) + 1f;
                });

            case Ease.InOutExpo:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if (time == 0f)
                    {
                        return 0f;
                    }
                    if (time == duration)
                    {
                        return 1f;
                    }
                    if ((time /= duration * 0.5f) < 1f)
                    {
                        return 0.5f * (float)Math.Pow(2.0, (double)(10f * (time - 1f)));
                    }
                    return 0.5f * (-(float)Math.Pow(2.0, (double)(-10f * (time -= 1f))) + 2f);
                });

            case Ease.InCirc:
                return((float time, float duration, float overshootOrAmplitude, float period) => - ((float)Math.Sqrt((double)(1f - (time /= duration) * time)) - 1f));

            case Ease.OutCirc:
                return((float time, float duration, float overshootOrAmplitude, float period) => (float)Math.Sqrt((double)(1f - (time = time / duration - 1f) * time)));

            case Ease.InOutCirc:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if ((time /= duration * 0.5f) < 1f)
                    {
                        return -0.5f * ((float)Math.Sqrt((double)(1f - time * time)) - 1f);
                    }
                    return 0.5f * ((float)Math.Sqrt((double)(1f - (time -= 2f) * time)) + 1f);
                });

            case Ease.InElastic:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if (time == 0f)
                    {
                        return 0f;
                    }
                    if ((time /= duration) == 1f)
                    {
                        return 1f;
                    }
                    if (period == 0f)
                    {
                        period = duration * 0.3f;
                    }
                    float num;
                    if (overshootOrAmplitude < 1f)
                    {
                        overshootOrAmplitude = 1f;
                        num = period / 4f;
                    }
                    else
                    {
                        num = period / 6.28318548f * (float)Math.Asin((double)(1f / overshootOrAmplitude));
                    }
                    return -(overshootOrAmplitude * (float)Math.Pow(2.0, (double)(10f * (time -= 1f))) * (float)Math.Sin((double)((time * duration - num) * 6.28318548f / period)));
                });

            case Ease.OutElastic:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if (time == 0f)
                    {
                        return 0f;
                    }
                    if ((time /= duration) == 1f)
                    {
                        return 1f;
                    }
                    if (period == 0f)
                    {
                        period = duration * 0.3f;
                    }
                    float num;
                    if (overshootOrAmplitude < 1f)
                    {
                        overshootOrAmplitude = 1f;
                        num = period / 4f;
                    }
                    else
                    {
                        num = period / 6.28318548f * (float)Math.Asin((double)(1f / overshootOrAmplitude));
                    }
                    return overshootOrAmplitude * (float)Math.Pow(2.0, (double)(-10f * time)) * (float)Math.Sin((double)((time * duration - num) * 6.28318548f / period)) + 1f;
                });

            case Ease.InOutElastic:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if (time == 0f)
                    {
                        return 0f;
                    }
                    if ((time /= duration * 0.5f) == 2f)
                    {
                        return 1f;
                    }
                    if (period == 0f)
                    {
                        period = duration * 0.450000018f;
                    }
                    float num;
                    if (overshootOrAmplitude < 1f)
                    {
                        overshootOrAmplitude = 1f;
                        num = period / 4f;
                    }
                    else
                    {
                        num = period / 6.28318548f * (float)Math.Asin((double)(1f / overshootOrAmplitude));
                    }
                    if (time < 1f)
                    {
                        return -0.5f * (overshootOrAmplitude * (float)Math.Pow(2.0, (double)(10f * (time -= 1f))) * (float)Math.Sin((double)((time * duration - num) * 6.28318548f / period)));
                    }
                    return overshootOrAmplitude * (float)Math.Pow(2.0, (double)(-10f * (time -= 1f))) * (float)Math.Sin((double)((time * duration - num) * 6.28318548f / period)) * 0.5f + 1f;
                });

            case Ease.InBack:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time /= duration) * time * ((overshootOrAmplitude + 1f) * time - overshootOrAmplitude));

            case Ease.OutBack:
                return((float time, float duration, float overshootOrAmplitude, float period) => (time = time / duration - 1f) * time * ((overshootOrAmplitude + 1f) * time + overshootOrAmplitude) + 1f);

            case Ease.InOutBack:
                return(delegate(float time, float duration, float overshootOrAmplitude, float period)
                {
                    if ((time /= duration * 0.5f) < 1f)
                    {
                        return 0.5f * (time * time * (((overshootOrAmplitude *= 1.525f) + 1f) * time - overshootOrAmplitude));
                    }
                    return 0.5f * ((time -= 2f) * time * (((overshootOrAmplitude *= 1.525f) + 1f) * time + overshootOrAmplitude) + 2f);
                });

            case Ease.InBounce:
                return((float time, float duration, float overshootOrAmplitude, float period) => Bounce.EaseIn(time, duration, overshootOrAmplitude, period));

            case Ease.OutBounce:
                return((float time, float duration, float overshootOrAmplitude, float period) => Bounce.EaseOut(time, duration, overshootOrAmplitude, period));

            case Ease.InOutBounce:
                return((float time, float duration, float overshootOrAmplitude, float period) => Bounce.EaseInOut(time, duration, overshootOrAmplitude, period));

            default:
                return((float time, float duration, float overshootOrAmplitude, float period) => - (time /= duration) * (time - 2f));
            }
        }
Exemple #3
0
        public static float Evaluate(Ease easeType, EaseFunction customEase, float time, float duration, float overshootOrAmplitude, float period)
        {
            switch (easeType)
            {
            case Ease.Linear:
                return(time / duration);

            case Ease.InSine:
                return(-(float)Math.Cos((double)(time / duration * 1.57079637f)) + 1f);

            case Ease.OutSine:
                return((float)Math.Sin((double)(time / duration * 1.57079637f)));

            case Ease.InOutSine:
                return(-0.5f * ((float)Math.Cos((double)(3.14159274f * time / duration)) - 1f));

            case Ease.InQuad:
                return((time /= duration) * time);

            case Ease.OutQuad:
                return(-(time /= duration) * (time - 2f));

            case Ease.InOutQuad:
                if ((time /= duration * 0.5f) < 1f)
                {
                    return(0.5f * time * time);
                }
                return(-0.5f * ((time -= 1f) * (time - 2f) - 1f));

            case Ease.InCubic:
                return((time /= duration) * time * time);

            case Ease.OutCubic:
                return((time = time / duration - 1f) * time * time + 1f);

            case Ease.InOutCubic:
                if ((time /= duration * 0.5f) < 1f)
                {
                    return(0.5f * time * time * time);
                }
                return(0.5f * ((time -= 2f) * time * time + 2f));

            case Ease.InQuart:
                return((time /= duration) * time * time * time);

            case Ease.OutQuart:
                return(-((time = time / duration - 1f) * time * time * time - 1f));

            case Ease.InOutQuart:
                if ((time /= duration * 0.5f) < 1f)
                {
                    return(0.5f * time * time * time * time);
                }
                return(-0.5f * ((time -= 2f) * time * time * time - 2f));

            case Ease.InQuint:
                return((time /= duration) * time * time * time * time);

            case Ease.OutQuint:
                return((time = time / duration - 1f) * time * time * time * time + 1f);

            case Ease.InOutQuint:
                if ((time /= duration * 0.5f) < 1f)
                {
                    return(0.5f * time * time * time * time * time);
                }
                return(0.5f * ((time -= 2f) * time * time * time * time + 2f));

            case Ease.InExpo:
                if (time != 0f)
                {
                    return((float)Math.Pow(2.0, (double)(10f * (time / duration - 1f))));
                }
                return(0f);

            case Ease.OutExpo:
                if (time == duration)
                {
                    return(1f);
                }
                return(-(float)Math.Pow(2.0, (double)(-10f * time / duration)) + 1f);

            case Ease.InOutExpo:
                if (time == 0f)
                {
                    return(0f);
                }
                if (time == duration)
                {
                    return(1f);
                }
                if ((time /= duration * 0.5f) < 1f)
                {
                    return(0.5f * (float)Math.Pow(2.0, (double)(10f * (time - 1f))));
                }
                return(0.5f * (-(float)Math.Pow(2.0, (double)(-10f * (time -= 1f))) + 2f));

            case Ease.InCirc:
                return(-((float)Math.Sqrt((double)(1f - (time /= duration) * time)) - 1f));

            case Ease.OutCirc:
                return((float)Math.Sqrt((double)(1f - (time = time / duration - 1f) * time)));

            case Ease.InOutCirc:
                if ((time /= duration * 0.5f) < 1f)
                {
                    return(-0.5f * ((float)Math.Sqrt((double)(1f - time * time)) - 1f));
                }
                return(0.5f * ((float)Math.Sqrt((double)(1f - (time -= 2f) * time)) + 1f));

            case Ease.InElastic:
            {
                if (time == 0f)
                {
                    return(0f);
                }
                if ((time /= duration) == 1f)
                {
                    return(1f);
                }
                if (period == 0f)
                {
                    period = duration * 0.3f;
                }
                float num;
                if (overshootOrAmplitude < 1f)
                {
                    overshootOrAmplitude = 1f;
                    num = period / 4f;
                }
                else
                {
                    num = period / 6.28318548f * (float)Math.Asin((double)(1f / overshootOrAmplitude));
                }
                return(-(overshootOrAmplitude * (float)Math.Pow(2.0, (double)(10f * (time -= 1f))) * (float)Math.Sin((double)((time * duration - num) * 6.28318548f / period))));
            }

            case Ease.OutElastic:
            {
                if (time == 0f)
                {
                    return(0f);
                }
                if ((time /= duration) == 1f)
                {
                    return(1f);
                }
                if (period == 0f)
                {
                    period = duration * 0.3f;
                }
                float num2;
                if (overshootOrAmplitude < 1f)
                {
                    overshootOrAmplitude = 1f;
                    num2 = period / 4f;
                }
                else
                {
                    num2 = period / 6.28318548f * (float)Math.Asin((double)(1f / overshootOrAmplitude));
                }
                return(overshootOrAmplitude * (float)Math.Pow(2.0, (double)(-10f * time)) * (float)Math.Sin((double)((time * duration - num2) * 6.28318548f / period)) + 1f);
            }

            case Ease.InOutElastic:
            {
                if (time == 0f)
                {
                    return(0f);
                }
                if ((time /= duration * 0.5f) == 2f)
                {
                    return(1f);
                }
                if (period == 0f)
                {
                    period = duration * 0.450000018f;
                }
                float num3;
                if (overshootOrAmplitude < 1f)
                {
                    overshootOrAmplitude = 1f;
                    num3 = period / 4f;
                }
                else
                {
                    num3 = period / 6.28318548f * (float)Math.Asin((double)(1f / overshootOrAmplitude));
                }
                if (time < 1f)
                {
                    return(-0.5f * (overshootOrAmplitude * (float)Math.Pow(2.0, (double)(10f * (time -= 1f))) * (float)Math.Sin((double)((time * duration - num3) * 6.28318548f / period))));
                }
                return(overshootOrAmplitude * (float)Math.Pow(2.0, (double)(-10f * (time -= 1f))) * (float)Math.Sin((double)((time * duration - num3) * 6.28318548f / period)) * 0.5f + 1f);
            }

            case Ease.InBack:
                return((time /= duration) * time * ((overshootOrAmplitude + 1f) * time - overshootOrAmplitude));

            case Ease.OutBack:
                return((time = time / duration - 1f) * time * ((overshootOrAmplitude + 1f) * time + overshootOrAmplitude) + 1f);

            case Ease.InOutBack:
                if ((time /= duration * 0.5f) < 1f)
                {
                    return(0.5f * (time * time * (((overshootOrAmplitude *= 1.525f) + 1f) * time - overshootOrAmplitude)));
                }
                return(0.5f * ((time -= 2f) * time * (((overshootOrAmplitude *= 1.525f) + 1f) * time + overshootOrAmplitude) + 2f));

            case Ease.InBounce:
                return(Bounce.EaseIn(time, duration, overshootOrAmplitude, period));

            case Ease.OutBounce:
                return(Bounce.EaseOut(time, duration, overshootOrAmplitude, period));

            case Ease.InOutBounce:
                return(Bounce.EaseInOut(time, duration, overshootOrAmplitude, period));

            case Ease.INTERNAL_Zero:
                return(1f);

            case Ease.INTERNAL_Custom:
                return(customEase(time, duration, overshootOrAmplitude, period));

            default:
                return(-(time /= duration) * (time - 2f));
            }
        }
Exemple #4
0
        /// <summary>
        /// Returns a value between 0 and 1 (inclusive) based on the elapsed time and ease selected
        /// </summary>
        public static float Evaluate(Ease easeType, EaseFunction customEase, float time, float duration, float overshootOrAmplitude, float period)
        {
            switch (easeType)
            {
            case Ease.Linear:
                return(time / duration);

            case Ease.InSine:
                return(-(float)Math.Cos(time / duration * _PiOver2) + 1);

            case Ease.OutSine:
                return((float)Math.Sin(time / duration * _PiOver2));

            case Ease.InOutSine:
                return(-0.5f * ((float)Math.Cos(Mathf.PI * time / duration) - 1));

            case Ease.InQuad:
                return((time /= duration) * time);

            case Ease.OutQuad:
                return(-(time /= duration) * (time - 2));

            case Ease.InOutQuad:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(0.5f * time * time);
                }
                return(-0.5f * ((--time) * (time - 2) - 1));

            case Ease.InCubic:
                return((time /= duration) * time * time);

            case Ease.OutCubic:
                return((time = time / duration - 1) * time * time + 1);

            case Ease.InOutCubic:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(0.5f * time * time * time);
                }
                return(0.5f * ((time -= 2) * time * time + 2));

            case Ease.InQuart:
                return((time /= duration) * time * time * time);

            case Ease.OutQuart:
                return(-((time = time / duration - 1) * time * time * time - 1));

            case Ease.InOutQuart:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(0.5f * time * time * time * time);
                }
                return(-0.5f * ((time -= 2) * time * time * time - 2));

            case Ease.InQuint:
                return((time /= duration) * time * time * time * time);

            case Ease.OutQuint:
                return((time = time / duration - 1) * time * time * time * time + 1);

            case Ease.InOutQuint:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(0.5f * time * time * time * time * time);
                }
                return(0.5f * ((time -= 2) * time * time * time * time + 2));

            case Ease.InExpo:
                return((time == 0) ? 0 : (float)Math.Pow(2, 10 * (time / duration - 1)));

            case Ease.OutExpo:
                if (time == duration)
                {
                    return(1);
                }
                return(-(float)Math.Pow(2, -10 * time / duration) + 1);

            case Ease.InOutExpo:
                if (time == 0)
                {
                    return(0);
                }
                if (time == duration)
                {
                    return(1);
                }
                if ((time /= duration * 0.5f) < 1)
                {
                    return(0.5f * (float)Math.Pow(2, 10 * (time - 1)));
                }
                return(0.5f * (-(float)Math.Pow(2, -10 * --time) + 2));

            case Ease.InCirc:
                return(-((float)Math.Sqrt(1 - (time /= duration) * time) - 1));

            case Ease.OutCirc:
                return((float)Math.Sqrt(1 - (time = time / duration - 1) * time));

            case Ease.InOutCirc:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(-0.5f * ((float)Math.Sqrt(1 - time * time) - 1));
                }
                return(0.5f * ((float)Math.Sqrt(1 - (time -= 2) * time) + 1));

            case Ease.InElastic:
                float s0;
                if (time == 0)
                {
                    return(0);
                }
                if ((time /= duration) == 1)
                {
                    return(1);
                }
                if (period == 0)
                {
                    period = duration * 0.3f;
                }
                if (overshootOrAmplitude < 1)
                {
                    overshootOrAmplitude = 1;
                    s0 = period / 4;
                }
                else
                {
                    s0 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
                }
                return(-(overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s0) * _TwoPi / period)));

            case Ease.OutElastic:
                float s1;
                if (time == 0)
                {
                    return(0);
                }
                if ((time /= duration) == 1)
                {
                    return(1);
                }
                if (period == 0)
                {
                    period = duration * 0.3f;
                }
                if (overshootOrAmplitude < 1)
                {
                    overshootOrAmplitude = 1;
                    s1 = period / 4;
                }
                else
                {
                    s1 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
                }
                return(overshootOrAmplitude * (float)Math.Pow(2, -10 * time) * (float)Math.Sin((time * duration - s1) * _TwoPi / period) + 1);

            case Ease.InOutElastic:
                float s;
                if (time == 0)
                {
                    return(0);
                }
                if ((time /= duration * 0.5f) == 2)
                {
                    return(1);
                }
                if (period == 0)
                {
                    period = duration * (0.3f * 1.5f);
                }
                if (overshootOrAmplitude < 1)
                {
                    overshootOrAmplitude = 1;
                    s = period / 4;
                }
                else
                {
                    s = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
                }
                if (time < 1)
                {
                    return(-0.5f * (overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period)));
                }
                return(overshootOrAmplitude * (float)Math.Pow(2, -10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period) * 0.5f + 1);

            case Ease.InBack:
                return((time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude));

            case Ease.OutBack:
                return((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1);

            case Ease.InOutBack:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(0.5f * (time * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time - overshootOrAmplitude)));
                }
                return(0.5f * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time + overshootOrAmplitude) + 2));

            case Ease.InBounce:
                return(Bounce.EaseIn(time, duration, overshootOrAmplitude, period));

            case Ease.OutBounce:
                return(Bounce.EaseOut(time, duration, overshootOrAmplitude, period));

            case Ease.InOutBounce:
                return(Bounce.EaseInOut(time, duration, overshootOrAmplitude, period));

            case Ease.INTERNAL_Custom:
                return(customEase(time, duration, overshootOrAmplitude, period));

            case Ease.INTERNAL_Zero:
                // 0 duration tween
                return(1);

            // Extra custom eases ////////////////////////////////////////////////////
            case Ease.Flash:
                return(Flash.Ease(time, duration, overshootOrAmplitude, period));

            case Ease.InFlash:
                return(Flash.EaseIn(time, duration, overshootOrAmplitude, period));

            case Ease.OutFlash:
                return(Flash.EaseOut(time, duration, overshootOrAmplitude, period));

            case Ease.InOutFlash:
                return(Flash.EaseInOut(time, duration, overshootOrAmplitude, period));

            // Default
            default:
                // OutQuad
                return(-(time /= duration) * (time - 2));
            }
        }
Exemple #5
0
 public static float EaseIn(float time, float duration, float unusedOvershootOrAmplitude, float unusedPeriod)
 {
     return(1f - Bounce.EaseOut(duration - time, duration, -1f, -1f));
 }
Exemple #6
0
        public static float Evaluate(Tween t, float time, float startValue, float changeValue, float duration, float overshootOrAmplitude, float period)
        {
            switch (t.easeType)
            {
            case Ease.Linear:
                return(changeValue * time / duration + startValue);

            case Ease.InSine:
                return(-changeValue * (float)Math.Cos(time / duration * _PiOver2) + changeValue + startValue);

            case Ease.OutSine:
                return(changeValue * (float)Math.Sin(time / duration * _PiOver2) + startValue);

            case Ease.InOutSine:
                return(-changeValue * 0.5f * ((float)Math.Cos(Mathf.PI * time / duration) - 1) + startValue);

            case Ease.InQuad:
                return(changeValue * (time /= duration) * time + startValue);

            case Ease.OutQuad:
                return(-changeValue * (time /= duration) * (time - 2) + startValue);

            case Ease.InOutQuad:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(changeValue * 0.5f * time * time + startValue);
                }
                return(-changeValue * 0.5f * ((--time) * (time - 2) - 1) + startValue);

            case Ease.InCubic:
                return(changeValue * (time /= duration) * time * time + startValue);

            case Ease.OutCubic:
                return(changeValue * ((time = time / duration - 1) * time * time + 1) + startValue);

            case Ease.InOutCubic:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(changeValue * 0.5f * time * time * time + startValue);
                }
                return(changeValue * 0.5f * ((time -= 2) * time * time + 2) + startValue);

            case Ease.InQuart:
                return(changeValue * (time /= duration) * time * time * time + startValue);

            case Ease.OutQuart:
                return(-changeValue * ((time = time / duration - 1) * time * time * time - 1) + startValue);

            case Ease.InOutQuart:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(changeValue * 0.5f * time * time * time * time + startValue);
                }
                return(-changeValue * 0.5f * ((time -= 2) * time * time * time - 2) + startValue);

            case Ease.InQuint:
                return(changeValue * (time /= duration) * time * time * time * time + startValue);

            case Ease.OutQuint:
                return(changeValue * ((time = time / duration - 1) * time * time * time * time + 1) + startValue);

            case Ease.InOutQuint:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(changeValue * 0.5f * time * time * time * time * time + startValue);
                }
                return(changeValue * 0.5f * ((time -= 2) * time * time * time * time + 2) + startValue);

            case Ease.InExpo:
                return((time == 0) ? startValue : changeValue *(float)Math.Pow(2, 10 * (time / duration - 1)) + startValue);

            case Ease.OutExpo:
                if (time == duration)
                {
                    return(startValue + changeValue);
                }
                return(changeValue * (-(float)Math.Pow(2, -10 * time / duration) + 1) + startValue);

            case Ease.InOutExpo:
                if (time == 0)
                {
                    return(startValue);
                }
                if (time == duration)
                {
                    return(startValue + changeValue);
                }
                if ((time /= duration * 0.5f) < 1)
                {
                    return(changeValue * 0.5f * (float)Math.Pow(2, 10 * (time - 1)) + startValue);
                }
                return(changeValue * 0.5f * (-(float)Math.Pow(2, -10 * --time) + 2) + startValue);

            case Ease.InCirc:
                return(-changeValue * ((float)Math.Sqrt(1 - (time /= duration) * time) - 1) + startValue);

            case Ease.OutCirc:
                return(changeValue * (float)Math.Sqrt(1 - (time = time / duration - 1) * time) + startValue);

            case Ease.InOutCirc:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(-changeValue * 0.5f * ((float)Math.Sqrt(1 - time * time) - 1) + startValue);
                }
                return(changeValue * 0.5f * ((float)Math.Sqrt(1 - (time -= 2) * time) + 1) + startValue);

            case Ease.InElastic:
                float s0;
                if (time == 0)
                {
                    return(startValue);
                }
                if ((time /= duration) == 1)
                {
                    return(startValue + changeValue);
                }
                if (period == 0)
                {
                    period = duration * 0.3f;
                }
                if (overshootOrAmplitude == 0 || (changeValue > 0 && overshootOrAmplitude < changeValue) || (changeValue < 0 && overshootOrAmplitude < -changeValue))
                {
                    overshootOrAmplitude = changeValue;
                    s0 = period / 4;
                }
                else
                {
                    s0 = period / _TwoPi * (float)Math.Asin(changeValue / overshootOrAmplitude);
                }
                return(-(overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s0) * _TwoPi / period)) + startValue);

            case Ease.OutElastic:
                float s1;
                if (time == 0)
                {
                    return(startValue);
                }
                if ((time /= duration) == 1)
                {
                    return(startValue + changeValue);
                }
                if (period == 0)
                {
                    period = duration * 0.3f;
                }
                if (overshootOrAmplitude == 0 || (changeValue > 0 && overshootOrAmplitude < changeValue) || (changeValue < 0 && overshootOrAmplitude < -changeValue))
                {
                    overshootOrAmplitude = changeValue;
                    s1 = period / 4;
                }
                else
                {
                    s1 = period / _TwoPi * (float)Math.Asin(changeValue / overshootOrAmplitude);
                }
                return(overshootOrAmplitude * (float)Math.Pow(2, -10 * time) * (float)Math.Sin((time * duration - s1) * _TwoPi / period) + changeValue + startValue);

            case Ease.InOutElastic:
                float s;
                if (time == 0)
                {
                    return(startValue);
                }
                if ((time /= duration * 0.5f) == 2)
                {
                    return(startValue + changeValue);
                }
                if (period == 0)
                {
                    period = duration * (0.3f * 1.5f);
                }
                if (overshootOrAmplitude == 0 || (changeValue > 0 && overshootOrAmplitude < changeValue) || (changeValue < 0 && overshootOrAmplitude < -changeValue))
                {
                    overshootOrAmplitude = changeValue;
                    s = period / 4;
                }
                else
                {
                    s = period / _TwoPi * (float)Math.Asin(changeValue / overshootOrAmplitude);
                }
                if (time < 1)
                {
                    return(-0.5f * (overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period)) + startValue);
                }
                return(overshootOrAmplitude * (float)Math.Pow(2, -10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period) * 0.5f + changeValue + startValue);

            case Ease.InBack:
                return(changeValue * (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude) + startValue);

            case Ease.OutBack:
                return(changeValue * ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1) + startValue);

            case Ease.InOutBack:
                if ((time /= duration * 0.5f) < 1)
                {
                    return(changeValue * 0.5f * (time * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time - overshootOrAmplitude)) + startValue);
                }
                return(changeValue / 2 * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time + overshootOrAmplitude) + 2) + startValue);

            case Ease.InBounce:
                return(Bounce.EaseIn(time, startValue, changeValue, duration, overshootOrAmplitude, period));

            case Ease.OutBounce:
                return(Bounce.EaseOut(time, startValue, changeValue, duration, overshootOrAmplitude, period));

            case Ease.InOutBounce:
                return(Bounce.EaseInOut(time, startValue, changeValue, duration, overshootOrAmplitude, period));

            case Ease.INTERNAL_Custom:
                return(t.customEase(time, startValue, changeValue, duration, overshootOrAmplitude, period));

            case Ease.INTERNAL_Zero:
                // 0 duration tween
                return(startValue + changeValue);

            default:
                // OutQuad
                return(-changeValue * (time /= duration) * (time - 2) + startValue);
            }
        }
 public static float InOutBounce(float time, float duration, float overshootOrAmplitude, float period)
 {
     return(Bounce.EaseInOut(time, duration, overshootOrAmplitude, period));
 }
Exemple #8
0
        public static EaseFunction ToEaseFunction(Ease ease)
        {
            switch (ease)
            {
            case Ease.Linear:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       time / duration);

            case Ease.InSine:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       - (float)Math.Cos(time / duration * _PiOver2) + 1);

            case Ease.OutSine:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (float)Math.Sin(time / duration * _PiOver2));

            case Ease.InOutSine:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       - 0.5f * ((float)Math.Cos(Mathf.PI * time / duration) - 1));

            case Ease.InQuad:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (time /= duration) * time);

            case Ease.OutQuad:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       - (time /= duration) * (time - 2));

            case Ease.InOutQuad:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if ((time /= duration * 0.5f) < 1)
                    {
                        return 0.5f * time * time;
                    }
                    return -0.5f * ((--time) * (time - 2) - 1);
                });

            case Ease.InCubic:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (time /= duration) * time * time);

            case Ease.OutCubic:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       ((time = time / duration - 1) * time * time + 1));

            case Ease.InOutCubic:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if ((time /= duration * 0.5f) < 1)
                    {
                        return 0.5f * time * time * time;
                    }
                    return 0.5f * ((time -= 2) * time * time + 2);
                });

            case Ease.InQuart:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (time /= duration) * time * time * time);

            case Ease.OutQuart:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       - ((time = time / duration - 1) * time * time * time - 1));

            case Ease.InOutQuart:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if ((time /= duration * 0.5f) < 1)
                    {
                        return 0.5f * time * time * time * time;
                    }
                    return -0.5f * ((time -= 2) * time * time * time - 2);
                });

            case Ease.InQuint:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (time /= duration) * time * time * time * time);

            case Ease.OutQuint:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       ((time = time / duration - 1) * time * time * time * time + 1));

            case Ease.InOutQuint:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if ((time /= duration * 0.5f) < 1)
                    {
                        return 0.5f * time * time * time * time * time;
                    }
                    return 0.5f * ((time -= 2) * time * time * time * time + 2);
                });

            case Ease.InExpo:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (time == 0) ? 0 : (float)Math.Pow(2, 10 * (time / duration - 1)));

            case Ease.OutExpo:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if (time == duration)
                    {
                        return 1;
                    }
                    return (-(float)Math.Pow(2, -10 * time / duration) + 1);
                });

            case Ease.InOutExpo:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if (time == 0)
                    {
                        return 0;
                    }
                    if (time == duration)
                    {
                        return 1;
                    }
                    if ((time /= duration * 0.5f) < 1)
                    {
                        return 0.5f * (float)Math.Pow(2, 10 * (time - 1));
                    }
                    return 0.5f * (-(float)Math.Pow(2, -10 * --time) + 2);
                });

            case Ease.InCirc:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       - ((float)Math.Sqrt(1 - (time /= duration) * time) - 1));

            case Ease.OutCirc:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (float)Math.Sqrt(1 - (time = time / duration - 1) * time));

            case Ease.InOutCirc:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if ((time /= duration * 0.5f) < 1)
                    {
                        return -0.5f * ((float)Math.Sqrt(1 - time * time) - 1);
                    }
                    return 0.5f * ((float)Math.Sqrt(1 - (time -= 2) * time) + 1);
                });

            case Ease.InElastic:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    float s0;
                    if (time == 0)
                    {
                        return 0;
                    }
                    if ((time /= duration) == 1)
                    {
                        return 1;
                    }
                    if (period == 0)
                    {
                        period = duration * 0.3f;
                    }
                    if (overshootOrAmplitude < 1)
                    {
                        overshootOrAmplitude = 1;
                        s0 = period / 4;
                    }
                    else
                    {
                        s0 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
                    }
                    return -(overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s0) * _TwoPi / period));
                });

            case Ease.OutElastic:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    float s1;
                    if (time == 0)
                    {
                        return 0;
                    }
                    if ((time /= duration) == 1)
                    {
                        return 1;
                    }
                    if (period == 0)
                    {
                        period = duration * 0.3f;
                    }
                    if (overshootOrAmplitude < 1)
                    {
                        overshootOrAmplitude = 1;
                        s1 = period / 4;
                    }
                    else
                    {
                        s1 = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
                    }
                    return (overshootOrAmplitude * (float)Math.Pow(2, -10 * time) * (float)Math.Sin((time * duration - s1) * _TwoPi / period) + 1);
                });

            case Ease.InOutElastic:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    float s;
                    if (time == 0)
                    {
                        return 0;
                    }
                    if ((time /= duration * 0.5f) == 2)
                    {
                        return 1;
                    }
                    if (period == 0)
                    {
                        period = duration * (0.3f * 1.5f);
                    }
                    if (overshootOrAmplitude < 1)
                    {
                        overshootOrAmplitude = 1;
                        s = period / 4;
                    }
                    else
                    {
                        s = period / _TwoPi * (float)Math.Asin(1 / overshootOrAmplitude);
                    }
                    if (time < 1)
                    {
                        return -0.5f * (overshootOrAmplitude * (float)Math.Pow(2, 10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period));
                    }
                    return overshootOrAmplitude * (float)Math.Pow(2, -10 * (time -= 1)) * (float)Math.Sin((time * duration - s) * _TwoPi / period) * 0.5f + 1;
                });

            case Ease.InBack:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       (time /= duration) * time * ((overshootOrAmplitude + 1) * time - overshootOrAmplitude));

            case Ease.OutBack:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       ((time = time / duration - 1) * time * ((overshootOrAmplitude + 1) * time + overshootOrAmplitude) + 1));

            case Ease.InOutBack:
                return((float time, float duration, float overshootOrAmplitude, float period) => {
                    if ((time /= duration * 0.5f) < 1)
                    {
                        return 0.5f * (time * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time - overshootOrAmplitude));
                    }
                    return 0.5f * ((time -= 2) * time * (((overshootOrAmplitude *= (1.525f)) + 1) * time + overshootOrAmplitude) + 2);
                });

            case Ease.InBounce:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       Bounce.EaseIn(time, duration, overshootOrAmplitude, period));

            case Ease.OutBounce:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       Bounce.EaseOut(time, duration, overshootOrAmplitude, period));

            case Ease.InOutBounce:
                return((float time, float duration, float overshootOrAmplitude, float period) =>
                       Bounce.EaseInOut(time, duration, overshootOrAmplitude, period));

            default:
                // OutQuad
                return((float time, float duration, float overshootOrAmplitude, float period) => - (time /= duration) * (time - 2));
            }
        }