static AnimatorController BuildAnimationController(List <AnimationClip> clips, string name) { AnimatorController animatorController = AnimatorController.CreateAnimatorControllerAtPath(AnimationControllerPath + "/" + name + ".controller"); AnimatorControllerLayer layer = animatorController.GetLayer(0); UnityEditorInternal.StateMachine sm = layer.stateMachine; foreach (AnimationClip newClip in clips) { State state = sm.AddState(newClip.name); state.SetAnimationClip(newClip, layer); Transition trans = sm.AddAnyStateTransition(state); trans.RemoveCondition(0); } AssetDatabase.SaveAssets(); return(animatorController); }
private static State AddStateTransition(string path, AnimatorControllerLayer layer, State lastState) { UnityEditorInternal.StateMachine sm = layer.stateMachine; //根据动画文件读取它的AnimationClip对象 AnimationClip newClip = AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip)) as AnimationClip; AnimationUtility.SetAnimationType(newClip, ModelImporterAnimationType.Generic); //取出动画名子 添加到state里面 State state = sm.AddState(newClip.name); state.SetAnimationClip(newClip, layer); //把state添加在layer里面 if (lastState == null) { // sm.AddAnyStateTransition (state); } else { sm.AddTransition(lastState, state); } return(state); }