// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit
{
///
/// Extension methods for Unity's AnimationCurve class
///
public static class AnimationCurveExtensions
{
///
/// Returns the absolute duration of the curve from first to last key frame
///
/// The animation curve to check duration of.
/// Returns 0 if the curve is null or has less than 1 frame, otherwise returns time difference between first and last frame.
public static float Duration(this AnimationCurve curve)
{
if (curve == null || curve.length <= 1)
{
return 0.0f;
}
return Mathf.Abs(curve[curve.length - 1].time - curve[0].time);
}
}
}