1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | public static class EasingFunctions { private const float halfPi = Mathf.PI * 0.5f; /// <summary> /// A linear progress scale function. /// </summary> public static readonly Func<float, float> Linear = linear; private static float linear(float progress) { return progress; } /// <summary> /// A quadratic (x^2) progress scale function that eases in. /// </summary> public static readonly Func<float, float> QuadraticEaseIn = quadraticEaseIn; private static float quadraticEaseIn(float progress) { return EaseInPower(progress, 2); } /// <summary> /// A quadratic (x^2) progress scale function that eases out. /// </summary> public static readonly Func<float, float> QuadraticEaseOut = quadraticEaseOut; private static float quadraticEaseOut(float progress) { return EaseOutPower(progress, 2); } /// <summary> /// A quadratic (x^2) progress scale function that eases in and out. /// </summary> public static readonly Func<float, float> QuadraticEaseInOut = quadraticEaseInOut; private static float quadraticEaseInOut(float progress) { return EaseInOutPower(progress, 2); } /// <summary> /// A cubic (x^3) progress scale function that eases in. /// </summary> public static readonly Func<float, float> CubicEaseIn = cubicEaseIn; private static float cubicEaseIn(float progress) { return EaseInPower(progress, 3); } /// <summary> /// A cubic (x^3) progress scale function that eases out. /// </summary> public static readonly Func<float, float> CubicEaseOut = cubicEaseOut; private static float cubicEaseOut(float progress) { return EaseOutPower(progress, 3); } /// <summary> /// A cubic (x^3) progress scale function that eases in and out. /// </summary> public static readonly Func<float, float> CubicEaseInOut = cubicEaseInOut; private static float cubicEaseInOut(float progress) { return EaseInOutPower(progress, 3); } /// <summary> /// A quartic (x^4) progress scale function that eases in. /// </summary> public static readonly Func<float, float> QuarticEaseIn = quarticEaseIn; private static float quarticEaseIn(float progress) { return EaseInPower(progress, 4); } /// <summary> /// A quartic (x^4) progress scale function that eases out. /// </summary> public static readonly Func<float, float> QuarticEaseOut = quarticEaseOut; private static float quarticEaseOut(float progress) { return EaseOutPower(progress, 4); } /// <summary> /// A quartic (x^4) progress scale function that eases in and out. /// </summary> public static readonly Func<float, float> QuarticEaseInOut = quarticEaseInOut; private static float quarticEaseInOut(float progress) { return EaseInOutPower(progress, 4); } /// <summary> /// A quintic (x^5) progress scale function that eases in. /// </summary> public static readonly Func<float, float> QuinticEaseIn = quinticEaseIn; private static float quinticEaseIn(float progress) { return EaseInPower(progress, 5); } /// <summary> /// A quintic (x^5) progress scale function that eases out. /// </summary> public static readonly Func<float, float> QuinticEaseOut = quinticEaseOut; private static float quinticEaseOut(float progress) { return EaseOutPower(progress, 5); } /// <summary> /// A quintic (x^5) progress scale function that eases in and out. /// </summary> public static readonly Func<float, float> QuinticEaseInOut = quinticEaseInOut; private static float quinticEaseInOut(float progress) { return EaseInOutPower(progress, 5); } /// <summary> /// A sine progress scale function that eases in. /// </summary> public static readonly Func<float, float> SineEaseIn = sineEaseIn; private static float sineEaseIn(float progress) { return Mathf.Sin(progress * halfPi - halfPi) + 1; } /// <summary> /// A sine progress scale function that eases out. /// </summary> public static readonly Func<float, float> SineEaseOut = sineEaseOut; private static float sineEaseOut(float progress) { return Mathf.Sin(progress * halfPi); } /// <summary> /// A sine progress scale function that eases in and out. /// </summary> public static readonly Func<float, float> SineEaseInOut = sineEaseInOut; private static float sineEaseInOut(float progress) { return (Mathf.Sin(progress * Mathf.PI - halfPi) + 1) / 2; } private static float EaseInPower(float progress, int power) { return Mathf.Pow(progress, power); } private static float EaseOutPower(float progress, int power) { int sign = power % 2 == 0 ? -1 : 1; //Debug.Log("Progress::"+progress+" Power::"+power+" Sign::" + sign); //Debug.Log("Value::" + sign * (Mathf.Pow(progress - 1, power) + sign)); return (sign * (Mathf.Pow(progress - 1, power) + sign)); } private static float EaseInOutPower(float progress, int power) { progress *= 2.0f; if (progress < 1) { return Mathf.Pow(progress, power) / 2.0f; } else { int sign = power % 2 == 0 ? -1 : 1; return (sign / 2.0f * (Mathf.Pow(progress - 2, power) + sign * 2)); } } } | cs |
'게임 개발 > Unity3D' 카테고리의 다른 글
[Unity | 유니티] Serializable Class 활용하기 (30) | 2018.11.21 |
---|---|
[Unity | 유니티] 특정 디렉토리에서 프리팹 또는 파일 로드하기 (0) | 2018.11.15 |
[Unity | 유니티] WWW 호출 인터페이스 작성 (0) | 2018.03.04 |
[Unity | 유니티] 유니티 프로젝트 빌드 시 android sdk path 에러 해결방법 (1) | 2018.02.23 |
[Unity | 유니티] 플랫포머 무한 스크롤 배경 만들기 (2) | 2017.06.13 |