// Get a reference to the Animator Controller:
UnityEditorInternal.AnimatorController ac = GetComponent<Animator>().runtimeAnimatorController as UnityEditorInternal.AnimatorController;
// Number of layers:
int layerCount = ac.GetLayerCount();
Debug.Log(string.Format("Layer Count: {0}", layerCount));
// Names of each layer:
for (int layer = 0; layer < layerCount; layer++) {
Debug.Log(string.Format("Layer {0}: {1}", layer, ac.GetLayerName(layer)));
}
// States on layer 0:
UnityEditorInternal.StateMachine sm = ac.GetLayerStateMachine(0);
List<UnityEditorInternal.State> states = sm.statesRecursive; // Also: sm.states
foreach (UnityEditorInternal.State s in states) {
Debug.Log(string.Format("State: {0}", s.GetUniqueName()));
}
有一些方法在新的版本(4.6)中已经过期,但基本思路不变,先获取AnimatorController,然后获取Layer,根据Layer获取StateMachine,之后获取State的实例。
原帖地址:http://answers.unity3d.com/quest

本文介绍如何在Unity3D中利用Mecanim动画系统获取动画层和动画状态,尽管某些4.6版本的方法已过期,但基本流程包括获取AnimatorController,进一步获取Layer、StateMachine及State实例。对于初学者,由于Unity API的设计问题,如Animator.runtimeAnimatorController返回抽象基类,可能造成使用困扰,官方文档对此的说明也不够清晰。
最低0.47元/天 解锁文章
513

被折叠的 条评论
为什么被折叠?



