C# 如何在animator中获取状态?

C# 如何在animator中获取状态?,c#,unity3d,C#,Unity3d,如何从animator获取状态。我试图通过状态获取动画的剪辑长度,我现在遇到的问题是,下面的代码仅适用于动画剪辑,但是如果我有链接到同一剪辑的额外状态,它将不起作用 public static AnimationClip GetAnimationClip(Animator animator, string name) { //can't get data if no animator if (animator == null) return null;

如何从animator获取状态。我试图通过状态获取动画的剪辑长度,我现在遇到的问题是,下面的代码仅适用于动画剪辑,但是如果我有链接到同一剪辑的额外状态,它将不起作用

public static AnimationClip GetAnimationClip(Animator animator, string name)
{
    //can't get data if no animator
    if (animator == null)
        return null;

    //favor for above foreach due to performance issues
    for (int i = 0; i < animator.runtimeAnimatorController.animationClips.Length; i++)
    {
        if (animator.runtimeAnimatorController.animationClips[i].name == name)
            return animator.runtimeAnimatorController.animationClips[i];
    }

    Debug.LogError("Animation clip: " + name + " not found");
    return null;
}
公共静态AnimationClip GetAnimationClip(Animator Animator,字符串名称)
{
//如果没有动画师,则无法获取数据
if(animator==null)
返回null;
//由于性能问题,支持上述foreach
对于(int i=0;i


我可以得到
walk
剪辑,但是我不能得到
walk\u auto
剪辑,这是额外的状态。

walk\u auto
一个完全独立的动画,还是它是
walk
的复制状态?@Tom它是一个使用“walk”剪辑的复制状态。那么我想这就是为什么你不能得到
walk\u auto
。这是一个不同的
状态
行走
不是一个全新的动画剪辑。没错,这就是为什么上面的代码只适用于剪辑。但我需要的是从animator那里得到状态,并将剪辑附加到它上,这样我就可以得到剪辑的长度。