/// <summary> /// Returns an approximation for the greatest value along the curve. /// /// Unity doesn't provide a way to get the bounding box, so /// we'll cheat and just check a certain number of samples. /// </summary> /// <returns>The max value.</returns> /// <param name="extends">Extends.</param> public static float GetMaxValue(this AnimationCurve extends) { float max = extends[0].value; if (extends.length == 1) { return(max); } float startTime = extends.GetStartTime(); float lengthTime = extends.GetTimeLength(); float delta = CURVE_BOUNDS_DELTA * lengthTime; for (int index = 1; index < CURVE_BOUNDS_SAMPLES; index++) { float time = startTime + delta * index; max = HydraMathUtils.Max(max, extends.Evaluate(time)); } return(max); }
/// <summary> /// Gets the length of the curve. /// </summary> /// <returns>The time length.</returns> /// <param name="extends">Extends.</param> public static float GetTimeLength(this AnimationCurve extends) { return(extends.GetEndTime() - extends.GetStartTime()); }