/// /// MIT License - Copyright(c) 2019 Ugo Belfiore /// using UnityEngine; namespace PerspectiveSwitcher { public static class ExtAnimationCurve { public enum EaseType { LINEAR, EASE_IN_OUT, } /// /// return a color from a string /// public static float GetMaxValue(this AnimationCurve animationCurve, ref int index) { if (animationCurve.length == 0) { Debug.LogWarning("no keys"); index = -1; return (0); } index = 0; float maxValue = animationCurve[0].value; for (int i = 1; i < animationCurve.length; i++) { if (animationCurve[i].value > maxValue) { maxValue = animationCurve[i].value; index = i; } } return (maxValue); } /// /// return a color from a string /// public static float GetMinValue(this AnimationCurve animationCurve, ref int index) { if (animationCurve.length == 0) { Debug.LogWarning("no keys"); index = -1; return (0); } index = 0; float minValue = animationCurve[0].value; for (int i = 1; i < animationCurve.length; i++) { if (animationCurve[i].value < minValue) { minValue = animationCurve[i].value; index = i; } } return (minValue); } public static AnimationCurve GetDefaultCurve(EaseType easeType = EaseType.LINEAR) { switch (easeType) { case EaseType.LINEAR: AnimationCurve curveLinear = AnimationCurve.Linear(0, 0, 1, 1);// new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1)); //curveLinear.postWrapMode = WrapMode.Clamp; return (curveLinear); case EaseType.EASE_IN_OUT: AnimationCurve curveEased = AnimationCurve.EaseInOut(0, 0, 1, 1); return (curveEased); } return (new AnimationCurve()); } } }