随笔 - 56, 评论 - 7, 访问 - 191738

导航


  • 访问:191738次
  • 积分:582分
  • 排名:第38名
  • 随笔:56篇
  • 评论:7条

随笔分类

随笔档案

相册

最新评论

阅读排行榜

评论排行榜

unity3d 阅读(410) 评论(0)
using UnityEngine;
using UnityEditor;
using UnityEditor.Animations;
using System.Collections;
// Create a menu item that causes a new controller and statemachine to be created.
public class SM : MonoBehaviour
{
[MenuItem("MyMenu/Create Controller")]
static void CreateController()
{
// Creates the controller
var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Mecanim/StateMachineTransitions.controller");
// Add parameters
controller.AddParameter("TransitionNow", AnimatorControllerParameterType.Trigger);
controller.AddParameter("Reset", AnimatorControllerParameterType.Trigger);
controller.AddParameter("GotoB1", AnimatorControllerParameterType.Trigger);
controller.AddParameter("GotoC", AnimatorControllerParameterType.Trigger);
// Add StateMachines
var rootStateMachine = controller.layers[0].stateMachine;
var stateMachineA = rootStateMachine.AddStateMachine("smA");
var stateMachineB = rootStateMachine.AddStateMachine("smB");
var stateMachineC = stateMachineB.AddStateMachine("smC");
// Add States
var stateA1 = stateMachineA.AddState("stateA1");
var stateB1 = stateMachineB.AddState("stateB1");
var stateB2 = stateMachineB.AddState("stateB2");
stateMachineC.AddState("stateC1");
var stateC2 = stateMachineC.AddState("stateC2"); // don’t add an entry transition, should entry to state by default
// Add Transitions
var exitTransition = stateA1.AddExitTransition();
exitTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow");
exitTransition.duration = 0;
var resetTransition = rootStateMachine.AddAnyStateTransition(stateA1);
resetTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "Reset");
resetTransition.duration = 0;
var transitionB1 = stateMachineB.AddEntryTransition(stateB1);
transitionB1.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoB1");
stateMachineB.AddEntryTransition(stateB2);
stateMachineC.defaultState = stateC2;
var exitTransitionC2 = stateC2.AddExitTransition();
exitTransitionC2.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "TransitionNow");
exitTransitionC2.duration = 0;
var stateMachineTransition = rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineC);
stateMachineTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, "GotoC");
rootStateMachine.AddStateMachineTransition(stateMachineA, stateMachineB);
}
}


更多参考文章:
https://www.cnblogs.com/android-blogs/p/6087916.html
https://blog.csdn.net/qq_28849871/article/details/77914922
https://www.cnblogs.com/yaoh/p/5149568.html
http://www.xuanyusong.com/archives/2811?from=okbase.net


发表评论
切换编辑模式