关于unity2015及2017版
//Animator动画管理器
private Animator ator;
//Animator动画信息对象数组
private AnimatorStateInfo[] asiAry;
//便利输出 “Animator动画管理器”0层 所有存储的动画名称
void GetCurrentAnimationName() {
//获取 自身Animator动画管理器
anim=GetComponent<Animator>();
//获取 “Animator动画管理器”0层 所有存储的动画名称
asiAry=anim.GetCurrentAnimationClipState(0);
foreach(AnimationInfo item in asiAry)
{
Debug.Log( item.clip.name);
}
}
关于unity2020版-----------------------------------------------
void GetAnimatonClipAry()
{
//获取这个Animator组件上对应某一层的AnimatorController资源
AnimatorControllerLayer layer =((AnimatorController)GetComponent<Animator>().runtimeAnimatorController).layers[0];
AnimatorStateMachine sm = layer.stateMachine; //获取层状态机
ChildAnimatorState[] ams = sm.states;//获取该层状态机的子状态机
//下面的代码可以封装为一个函数,反复使用
for (int i=0;i<ams.Length;i++) {//因为u3d没有提供直接获取指定名字的state,所以我们必须历遍所有的去找我们想要的那个(耗性能)
//if(ams[i].state.name=="XXX")//获取名字为XXX的State
//ams[i].state.motion = mm;//改他Motion(动作)
Debug.Log(ams[i].state.name);
}
//如果你想获取当前的state信息 可以历遍时 用 animator.GetCurrentAnimatorStateInfo().IsName()去判定,如果成功就说明是当前的State
//这个方法很消耗性能,因为要循环一次,不过也值
}
》》》》如果不行的话
/// <summary> /// 获取Ator里面 所有动画剪辑的名称 /// </summary> public List<string> GetAnimatonClipAry2(Animator animator) { List<string> temp =new List<string>(); RuntimeAnimatorController ac = animator.runtimeAnimatorController; AnimationClip[] tAnimationClips = ac.animationClips; for (int i = 0; i < tAnimationClips.Length; i++) { //Debug.Log(+"名称"); temp.Add(tAnimationClips[i].name); } return temp; }