private void CreateStateMachine() { if (avatarPreview == null || avatarPreview.Animator == null) { return; } if (controller == null) { controller = new UnityEditor.Animations.AnimatorController(); controller.AddLayer("preview"); controller.hideFlags = HideFlags.DontSave; //stateMachine = controller.GetLayer(0).stateMachine; CreateParameters(); state = stateMachine.AddState("preview"); state.SetMotion(previewedMotion); state.iKOnFeet = avatarPreview.IKOnFeet; state.hideFlags = HideFlags.DontSave; UnityEditor.Animations.AnimatorController.SetAnimatorController(avatarPreview.Animator, controller); } //if (UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(avatarPreview.Animator) != this.controller) //{ // UnityEditor.Animations.AnimatorController.SetAnimatorController(avatarPreview.Animator, this.controller); //} }
private void AddBehaviorState(UnityEditor.Animations.AnimatorStateMachine rootStateMachine, string nameIn) { var new_state = rootStateMachine.AddState(nameIn); new_state.AddStateMachineBehaviour <CreaturePackStateMachineBehavior>(); CreaturePackStateMachineBehavior cur_behavior = (CreaturePackStateMachineBehavior)new_state.behaviours[0]; cur_behavior.play_animation_name = nameIn; }
static UnityEditor.Animations.AnimatorController BuildAnimationController(List <AnimationClip> clips, string name) { System.IO.Directory.CreateDirectory(animationControllerPath); UnityEditor.Animations.AnimatorController animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(animationControllerPath + "/" + name + ".controller"); UnityEditor.Animations.AnimatorControllerLayer layer = animatorController.layers[0]; UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine; foreach (AnimationClip newClip in clips) { UnityEditor.Animations.AnimatorState state = sm.AddState(newClip.name); state.motion = newClip; } AssetDatabase.SaveAssets(); return(animatorController); }
private static void AddStateTransition(string path, UnityEditor.Animations.AnimatorControllerLayer layer, string motionName, Vector3 pos) { UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine; Motion motion = AssetDatabase.LoadAssetAtPath(path, typeof(Motion)) as Motion; //根据动画文件读取它的Motion对象 UnityEditor.Animations.AnimatorState state = sm.AddState(motionName, pos); //motion.name state.motion = motion; //取出动画名子 添加到state里面 UnityEditor.Animations.AnimatorStateTransition trans = sm.AddAnyStateTransition(state); //把state添加在layer里面 trans.hasExitTime = false; //把默认的时间条件删除 //false //trans.exitTime = 1f; //0.9f trans.duration = 0f; //默认过渡时间 // 0.1f trans.canTransitionToSelf = true; //默认true }
public static AnimatorState addNoExistState(AnimatorControllerLayer layer, AnimationClip newClip, bool autoCreate = true) { if (newClip == null || layer == null) { return(null); } UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine; AnimatorState state = getExistState(sm, newClip.name); if (state == null) { state = sm.AddState(newClip.name); } state.motion = newClip; return(state); }
private static UnityEditor.Animations.AnimatorState CreateState(UnityEditor.Animations.AnimatorStateMachine machine, string name, AnimationClip anim, Vector3 pos) { foreach (var item in machine.states) { if (item.state.name == name) { return(item.state); } } UnityEditor.Animations.AnimatorState state = machine.AddState(name); state.motion = anim; //state.SetAnimationClip(anim); var state1 = ArrayUtility.Find <UnityEditor.Animations.ChildAnimatorState>(machine.states, x => x.state == state); state1.position = pos; //state.position = pos; return(state); }