Пример #1
0
        public static float GetNormalizedValue(this AnimationCurve curve, float t)
        {
            float tmin = curve.GetMinTime();
            float tmax = curve.GetMaxTime();
            float lerp = Mathf.Lerp(tmin, tmax, t);
            float v    = curve.Evaluate(lerp);

            tmin = curve.GetStartValue();
            tmax = curve.GetEndValue();
            float len = tmax - tmin;

            return(len == 0 ? v : (v - tmin) / len);
        }
        public static AnimationCurve Scale(this AnimationCurve animationCurve, float newScale)
        {
            float maxLenght   = animationCurve.GetMaxTime();
            float scaleFactor = newScale / maxLenght;

            Keyframe[] keys = animationCurve.keys;
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new Keyframe(keys[i].time * scaleFactor, keys[i].value);
            }
            animationCurve.keys = keys;

            return(animationCurve);
        }
Пример #3
0
 public static float ClampTime(this AnimationCurve curve, float time)
 {
     return(Mathf.Clamp(time, curve.GetMinTime(), curve.GetMaxTime()));
 }