代码添加动画控制器
1 // Creates the controller 2 var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath ("Assets/Mecanim/StateMachineTransitions.controller"); 3 4 // Add parameters 5 controller.AddParameter(“TransitionNow”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger); 6 controller.AddParameter(“Reset”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger); 7 controller.AddParameter(“GotoB1″, UnityEditor.Animations.AnimatorControllerParameterType.Trigger); 8 controller.AddParameter(“GotoC”, UnityEditor.Animations.AnimatorControllerParameterType.Trigger); 9 10 // Add StateMachines 11 var rootStateMachine = controller.layers[0].stateMachine; 12 var stateMachineA = rootStateMachine.AddStateMachine(“smA”); 13 var stateMachineB = rootStateMachine.AddStateMachine(“smB”); 14 var stateMachineC = stateMachineB.AddStateMachine(“smC”); 15 16 // Add States 17 var stateA1 = stateMachineA.AddState(“stateA1″); 18 var stateB1 = stateMachineB.AddState(“stateB1″); 19 var stateB2 = stateMachineB.AddState(“stateB2″); 20 stateMachineC.AddState(“stateC1″); 21 var stateC2 = stateMachineC.AddState(“stateC2″); // don’t add an entry transition, should entry to state by default 22 23 // Add Transitions 24 var exitTransition = stateA1.AddExitTransition(); 25 exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”); 26 exitTransition.duration = 0; 27 28 var resetTransition = stateMachineA.AddAnyStateTransition(stateA1); 29 resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “Reset”); 30 resetTransition.duration = 0; 31 32 var transitionB1 = stateMachineB.AddEntryTransition(stateB1); 33 transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoB1″); 34 stateMachineB.AddEntryTransition(stateB2); 35 stateMachineC.defaultState = stateC2; 36 var exitTransitionC2 = stateC2.AddExitTransition(); 37 exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “TransitionNow”); 38 exitTransitionC2.duration = 0; 39 40 var stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC); 41 stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, “GotoC”); 42 rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineB);