Unity通过Animator获取动画clip时长
程序员文章站
2022-05-04 12:04:54
...
///获取动画状态机animator的动画clip的播放持续时长
public static float GetClipLength(Animator animator, string clipName)
{
if(null== animator ||
string.IsNullOrEmpty(clip) ||
null == animator.runtimeAnimatorController)
return 0;
// 获取所有的clips
var clips = animator.runtimeAnimatorController.animationClips;
if( null == clips || clips.Length <= 0) return 0;
AnimationClip clip ;
for (int i = 0, len = clips.Length; i < len ; ++i)
{
clip = ac.animationClips[i];
if(null != clip && clip.name == clipName)
return clip.Length;
}
return 0f;
}