unity3d Mecanim动画系统获取动画层、动画状态等方法

来源:互联网 发布:淘宝发布网络推广类目 编辑:程序博客网 时间:2024/06/01 09:37
 // 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/questions/418854/getting-a-list-of-mecanim-states-in-animator.html



吐槽一下unity的API开发人员,居然给Animator.runtimeAnimatorController一个抽象的基类返回值,至少也搞一个能够返回AnimatorController的方法。还需要使用程序员强转一下,简直不人道。不知道的人,根本不知道如何用,而且貌似官方API文档也没有很好的说明。

1 0
原创粉丝点击