public void AddTransition(EditorAnimationItem Anim, AnimatorConditionMode mode, float v, string parameter, bool hasExitTime = true) { AnimatorStateTransition st = state.AddTransition(Anim.state); st.AddCondition(mode, v, parameter); st.hasExitTime = hasExitTime; }
void Create() { AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/" + target.name + ".controller"); // Adds a float parameter called Speed controller.AddParameter("Speed", AnimatorControllerParameterType.Float); //Add states AnimatorState idleState = controller.layers[0].stateMachine.AddState("Idle"); idleState.motion = idleAnim; //Blend tree creation BlendTree blendTree; AnimatorState moveState = controller.CreateBlendTreeInController("Move", out blendTree); //BlendTree setup blendTree.blendType = BlendTreeType.Simple1D; blendTree.blendParameter = "Speed"; blendTree.AddChild(walkAnim); blendTree.AddChild(runAnim); AnimatorStateTransition LeaveIdle = idleState.AddTransition(moveState); AnimatorStateTransition leaveMove = moveState.AddTransition(idleState); LeaveIdle.AddCondition(AnimatorConditionMode.Greater, 0.01f, "Speed"); leaveMove.AddCondition(AnimatorConditionMode.Less, 0.01f, "Speed"); target.GetComponent <Animator>().runtimeAnimatorController = controller; }
/// <summary> /// 给预制体添加动画 /// </summary> /// <param name="obj"></param> /// <param name="modelPath"></param> /// <param name="animatorControllerPath"></param> /// <param name="name"></param> public static void SetAnimatorController(GameObject obj, string modelPath, string animatorControllerPath, string name) { Animator anim = obj.GetComponent <Animator>(); if (anim) { AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath(animatorControllerPath + name + ".controller"); AnimatorController.SetAnimatorController(anim, controller); AnimatorControllerLayer layer = controller.layers[0]; AnimatorStateMachine machine = layer.stateMachine; controller.AddParameter("e", AnimatorControllerParameterType.Bool); AnimatorState IdleState = machine.AddState("Idle", new Vector3(300, 0, 0)); machine.defaultState = IdleState; AnimatorState behaviorState = machine.AddState("behavior", new Vector3(550, 0, 0)); behaviorState.motion = GetAnimationClip(modelPath); AnimatorStateTransition behaviorTrue = IdleState.AddTransition(behaviorState); behaviorTrue.AddCondition(AnimatorConditionMode.If, 1f, "e"); AnimatorStateTransition behaviorFlas = behaviorState.AddTransition(IdleState); behaviorFlas.AddCondition(AnimatorConditionMode.IfNot, 1F, "e"); } else { Debug.Log(obj.name + "没有挂载动画状态机组件"); } }
/// <summary> /// 创建动画控制器 /// </summary> /// <param name="obj"></param> /// <param name="path"></param> /// <returns></returns> private static AnimatorController CreateAnimatorController(Object obj, string path) { string assetPath = AssetDatabase.GetAssetPath(obj); AnimationClip animationClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(assetPath); AnimatorController animatorController = AnimatorController.CreateAnimatorControllerAtPath(path + "/" + obj.name + ".controller"); animatorController.AddParameter("isLoop", AnimatorControllerParameterType.Bool); AnimatorControllerLayer animatorControllerLayer = animatorController.layers[0]; AnimatorStateMachine animatorStateMachine = animatorControllerLayer.stateMachine; AnimatorState animatorState = animatorStateMachine.AddState(animationClip.name); animatorState.motion = animationClip; AnimatorState emptyState = animatorStateMachine.AddState("Empty", new Vector3(animatorStateMachine.entryPosition.x + 400, animatorStateMachine.entryPosition.y + 400, 0)); AnimatorStateTransition animatorStateTransition = animatorState.AddTransition(emptyState); animatorStateTransition.hasExitTime = true; animatorStateTransition = emptyState.AddTransition(animatorState); animatorStateTransition.AddCondition(AnimatorConditionMode.If, 1, "isLoop"); return(animatorController); }
public static AnimatorStateTransition AddTransitionDefaultParam(this AnimatorState sourceState, AnimatorState destinationState, bool addDefaultCondition = true) { var transition = sourceState.AddTransition(destinationState); SetDefaultTransitionParam(transition); return(transition); }
public static AnimatorStateTransition AddTransitionDefaultParam(this AnimatorState sourceState, AnimatorState destinationState, AnimatorCondition[] conditions) { var transition = sourceState.AddTransition(destinationState); SetDefaultTransitionParam(transition); transition.conditions = conditions; return(transition); }
protected AnimatorStateTransition AddTransition(AnimatorState baseState, AnimatorState endState) { var transition = baseState.AddTransition(endState); transition.duration = 0; transition.hasExitTime = false; return(transition); }
public static AnimatorStateTransition AddTransitionDefaultParam(this AnimatorState sourceState, AnimatorState destinationState, AnimatorConditionMode mode, float threshold, string parameter) { var transition = sourceState.AddTransition(destinationState); SetDefaultTransitionParam(transition); transition.AddCondition(mode, threshold, parameter); return(transition); }
//Crée un Dialog Controller (Animator Controller) qui a les caractéristiques suivantes : //Il possède tous les paramètres Triggers et Booléens nécessaires pour être utilisé. //Un état de départ et des transitions vers 2 états supplémentaires Visited et NotVisited. //Une transition de retour depuis AnyState permet de revenir à l'état initial dès que le booléen active redevient faux. //Les transitions sont configurées correctement (pas de durée de transition). void CreateController() { var controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/DialogControllers/" + controllerName + ".controller"); var rootStateMachine = controller.layers[0].stateMachine; controller.AddParameter(DialogParameters.nextString, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.answer0String, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.answer1String, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.answer2String, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.answer3String, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.itemConditionMetString, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.itemConditionNotMetString, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.valueConditionMetString, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.valueConditionNotMetString, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.randomSuccess, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.randomFailure, AnimatorControllerParameterType.Trigger); controller.AddParameter(DialogParameters.visitedString, AnimatorControllerParameterType.Bool); controller.AddParameter(DialogParameters.activeString, AnimatorControllerParameterType.Bool); AnimatorState startState = rootStateMachine.AddState("Start") as AnimatorState; rootStateMachine.AddEntryTransition(startState); AnimatorState notVisitedState = rootStateMachine.AddState("Not Visited") as AnimatorState; AnimatorStateTransition notVisitedTransition = startState.AddTransition(notVisitedState) as AnimatorStateTransition; notVisitedTransition.duration = 0f; notVisitedTransition.AddCondition(AnimatorConditionMode.IfNot, 0, DialogParameters.visitedString); notVisitedTransition.AddCondition(AnimatorConditionMode.If, 0, DialogParameters.activeString); AnimatorState visitedState = rootStateMachine.AddState("Visited") as AnimatorState; AnimatorStateTransition visitedTransition = startState.AddTransition(visitedState) as AnimatorStateTransition; visitedTransition.duration = 0f; visitedTransition.AddCondition(AnimatorConditionMode.If, 0, DialogParameters.visitedString); visitedTransition.AddCondition(AnimatorConditionMode.If, 0, DialogParameters.activeString); AnimatorStateTransition inactiveTransition = rootStateMachine.AddAnyStateTransition(startState) as AnimatorStateTransition; inactiveTransition.duration = 0f; inactiveTransition.AddCondition(AnimatorConditionMode.IfNot, 0, DialogParameters.activeString); }
private void CopyOrCreateTransition(AnimatorStateTransition refTransition, AnimatorState outStartState, AnimatorState outEndState) { AnimatorStateTransition outTransition = FindTransitionA2B(outStartState, outEndState); if (outTransition == null) { outTransition = outStartState.AddTransition(outEndState); } CopyStateTransition(refTransition, outTransition); }
protected void AddDirectionTransitionA2BIfNotExist(AnimatorState stateA, AnimatorState stateB, int angle) { AnimatorStateTransition transition = FindTransitionA2B(stateA, stateB); if (transition == null) { transition = stateA.AddTransition(stateB); } RemoveAllAndAddCondition(transition, ANGLE_PARAM_NAME, AnimatorConditionMode.Equals, angle); }
void Build() { controller = AnimatorController.CreateAnimatorControllerAtPath("Assets/Scripts/Controllers/" + targetM.name + ".controller"); controller.AddParameter("Speed", AnimatorControllerParameterType.Float); controller.AddParameter("IsJump", AnimatorControllerParameterType.Trigger); var rootMachine = controller.layers[0].stateMachine; BlendTree blendTree1; BlendTree blendTree2; AnimatorState idleState = rootMachine.AddState("Idle"); AnimatorState jumpState = rootMachine.AddState("Jump"); AnimatorState moveState1 = controller.CreateBlendTreeInController("Move Forward", out blendTree1); AnimatorState moveState2 = controller.CreateBlendTreeInController("Move Backward", out blendTree2); idleState.motion = idleAnim; jumpState.motion = jumpAnim; blendTree1.blendType = BlendTreeType.Simple1D; blendTree2.blendType = BlendTreeType.Simple1D; blendTree1.blendParameter = "Speed"; blendTree2.blendParameter = "Speed"; blendTree1.AddChild(walkFore); blendTree1.AddChild(runFore); blendTree2.AddChild(walkBack); blendTree2.AddChild(runBack); AnimatorStateTransition leaveIFore = idleState.AddTransition(moveState1); AnimatorStateTransition leaveMFore = moveState1.AddTransition(idleState); AnimatorStateTransition leaveIBack = idleState.AddTransition(moveState2); AnimatorStateTransition leaveMBack = moveState2.AddTransition(idleState); AnimatorStateTransition jumpUp = idleState.AddTransition(jumpState); AnimatorStateTransition jumpDown = jumpState.AddTransition(idleState, true); leaveIFore.AddCondition(AnimatorConditionMode.Greater, 0.01f, "Speed"); leaveMFore.AddCondition(AnimatorConditionMode.Less, 0.01f, "Speed"); leaveIBack.AddCondition(AnimatorConditionMode.Less, -0.01f, "Speed"); leaveMBack.AddCondition(AnimatorConditionMode.Greater, -0.01f, "Speed"); jumpUp.AddCondition(AnimatorConditionMode.If, 0, "IsJump"); targetM.GetComponent <Animator>().runtimeAnimatorController = controller; }
private void CreateTransitionWhenActivityIsOutOfBounds(AnimatorState from, AnimatorState to) { var transition = from.AddTransition(to); SharedLayerUtils.SetupDefaultTransition(transition); foreach (var layer in _comboLayers) { transition.AddCondition(AnimatorConditionMode.NotEqual, layer.stageValue, _activityStageName); } }
private static void AddStateTransition(AnimatorController ctrl, string path, AnimatorControllerLayer layer) { AnimatorStateMachine sm = layer.stateMachine; //根据动画文件读取它的AnimationClip对象 Object[] objs = AssetDatabase.LoadAllAssetsAtPath(path); List <AnimationClip> clips = new List <AnimationClip>(); for (int i = 0; i < objs.Length; i++) { AnimationClip clip = objs[i] as AnimationClip; if (clip != null && clip.name.IndexOf("__preview__") == -1) { clips.Add(clip); } } AnimatorState idleState = null; List <AnimatorState> otherStates = new List <AnimatorState>(); foreach (AnimationClip newClip in clips) { AnimatorState state = sm.AddState(newClip.name); state.motion = newClip; if (newClip.name == CreateAnimatorController.IdleName) { idleState = state; } else { string cond = string.Format("{0}_{1}", CreateAnimatorController.IdleName, newClip.name); ctrl.AddParameter(cond, AnimatorControllerParameterType.Bool); cond = string.Format("{1}_{0}", CreateAnimatorController.IdleName, newClip.name); ctrl.AddParameter(cond, AnimatorControllerParameterType.Bool); otherStates.Add(state); } } sm.defaultState = idleState; foreach (AnimatorState state in otherStates) { string cond = string.Format("{0}_{1}", CreateAnimatorController.IdleName, state.motion.name); AnimatorStateTransition tran = idleState.AddTransition(state); tran.AddCondition(AnimatorConditionMode.If, 0, cond); cond = string.Format("{1}_{0}", CreateAnimatorController.IdleName, state.motion.name); tran = state.AddTransition(idleState); tran.AddCondition(AnimatorConditionMode.If, 0, cond); } }
/// <summary> /// 连闲置状态 /// </summary> /// <param name="newState"></param> /// <param name="entryState"></param> private void ConnectIdleState(AnimatorState newState, AnimatorState entryState) { if (newState == null || entryState == null) { return; } AnimatorStateTransition _animatorStateTransition = newState.AddTransition(entryState); _animatorStateTransition.hasExitTime = true; _animatorStateTransition.offset = 0; _animatorStateTransition.duration = 0; }
//Cette fonction crée un état avec les transitions spécifiées (durée, exit time, et conditions) par le choix dans CreateChildrenStateAndTransitions. void CreateStatesAndTriggerTransitions(AnimatorStateMachine stateMachine, AnimatorState origin, string[] triggers) { string newStateName = stateMachine.MakeUniqueStateName("newState"); AnimatorState newState = stateMachine.AddState(newStateName) as AnimatorState; AnimatorStateTransition newStateTransition = originState.AddTransition(newState) as AnimatorStateTransition; newStateTransition.hasExitTime = false; newStateTransition.duration = 0f; foreach (string trigger in triggers) { newStateTransition.AddCondition(AnimatorConditionMode.If, 0, trigger); } }
/// <summary> /// Show how to add transitions /// </summary> private void SetBaseLayerTransition() { var trans = stateIdle.AddTransition(stateMove); trans.hasExitTime = true; trans.exitTime = 0.9f; trans.interruptionSource = TransitionInterruptionSource.Source; trans.duration = 0; trans = stateMove.AddTransition(stateIdle); trans.interruptionSource = TransitionInterruptionSource.Destination; trans.duration = 0; trans.AddCondition(AnimatorConditionMode.If, 0, "TriggerA"); }
private void ConnectIdleStateByBool(AnimatorState newState, AnimatorState entryState, string condName) { if (newState == null || entryState == null) { return; } AnimatorStateTransition _animatorStateTransition = newState.AddTransition(entryState); if (newState.name != IdleStateName) { _animatorStateTransition.AddCondition(AnimatorConditionMode.IfNot, 0, condName); } _animatorStateTransition.hasExitTime = true; _animatorStateTransition.offset = 0; _animatorStateTransition.duration = 0; }
void AddState(int indexBlendTreeOffset, AnimatorController controller, AnimatorStateMachine sm, int layer, ClipIDPair clipIDPair, AnimatorState[] blendTrees) { if (clipIDPair.layer != layer) { return; } if (clipIDPair.looped) { return; } int id = clipIDPair.id; AnimationClip clip = clipIDPair.clip; // Add the state to the state machine (The Vector3 is for positioning in the editor window) AnimatorState state = sm.AddState(id.ToString());//, new Vector3(300, 0, 0)); state.mirrorParameterActive = true; state.speedParameterActive = true; state.mirrorParameter = CustomAnimator.mirrorParamStrings[layer]; state.speedParameter = CustomAnimator.speedParamStrings[layer]; // state.mirrorParameter = CustomAnimator.sMirror; // state.speedParameter = CustomAnimator.sSpeed; state.tag = CustomAnimator.sShots; state.motion = clip; float exit_time = 1.0f - (exitTransitionDuration / clip.length); int c = blendTrees.Length; for (int i = 0; i < c; i++) { AnimatorStateTransition exit = state.AddTransition(blendTrees[i]); //exit.AddCondition(AnimatorConditionMode.Equals, i, CustomAnimator.sActiveLoop); exit.AddCondition(AnimatorConditionMode.Equals, i + indexBlendTreeOffset, CustomAnimator.activeLoopParamStrings[layer]); exit.canTransitionToSelf = false; exit.hasExitTime = true; exit.exitTime = exit_time; exit.hasFixedDuration = true; exit.duration = exitTransitionDuration; } }
private void CreateToggleLayer() { string layerName = "ToggleMarker"; AnimatorControllerLayer layer = FindLayer(layerName); if (layer == null) { layer = new AnimatorControllerLayer(); layer.name = layerName; layer.stateMachine = new AnimatorStateMachine(); layer.stateMachine.name = layerName; layer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath(fxController) != "") { AssetDatabase.AddObjectToAsset(layer.stateMachine, AssetDatabase.GetAssetPath(fxController)); } layer.blendingMode = AnimatorLayerBlendingMode.Override; layer.defaultWeight = 1.0f; AnimatorState MarkerOffState = layer.stateMachine.AddState("MarkerOff"); AnimatorState MarkerOnState = layer.stateMachine.AddState("MarkerOn"); AnimatorStateTransition transition = MarkerOffState.AddTransition(MarkerOnState); transition.AddCondition(AnimatorConditionMode.Equals, 1, "ToggleMarker"); transition.hasExitTime = false; transition.hasFixedDuration = false; transition.duration = 0; transition.interruptionSource = TransitionInterruptionSource.Destination; transition.canTransitionToSelf = false; transition = MarkerOnState.AddTransition(MarkerOffState); transition.AddCondition(AnimatorConditionMode.Equals, 0, "ToggleMarker"); transition.hasExitTime = false; transition.hasFixedDuration = false; transition.duration = 0; transition.interruptionSource = TransitionInterruptionSource.Destination; transition.canTransitionToSelf = false; WriteToggleAnimations(); MarkerOffState.motion = toggleOffClip; MarkerOnState.motion = toggleOnClip; fxController.AddLayer(layer); } }
private void UpdateAnimatorController() { // The new controller that will be created based on Manager animations AnimatorController newController = new AnimatorController(); newController.AddLayer("DefaultLayer"); // Add a parameter that will determine the animation states AnimatorControllerParameter animatorParameter = new AnimatorControllerParameter(); animatorParameter.type = AnimatorControllerParameterType.Int; animatorParameter.name = "TextAnimation"; animatorParameter.defaultInt = 999; newController.AddParameter(animatorParameter); // Add state machine AnimatorStateMachine rootStateMachine = newController.layers[0].stateMachine; AnimatorStateMachine stateMachine = rootStateMachine.AddStateMachine("TextAnimationStateMachine"); // Create a default state to prevent animation auto playing index 0 AnimatorState waitingState = stateMachine.AddState("Waiting"); //foreach (AnimationClip clip in DamageNumberManager.instance.animations) for (int i = 0; i < DamageNumberManager.instance.animations.Length; i++) { AnimationClip clip = DamageNumberManager.instance.animations[i]; // Add new state based on the AnimationClip AnimatorState state = stateMachine.AddState(clip.name); state.motion = clip; // Create transition from "Waiting" to the new state AnimatorStateTransition transition = waitingState.AddTransition(state, false); transition.AddCondition(AnimatorConditionMode.Equals, i, "TextAnimation"); } // Override the existing Animator Controller AnimatorOverrideController overrideController = new AnimatorOverrideController(); overrideController.runtimeAnimatorController = newController; GetComponent <Animator>().runtimeAnimatorController = overrideController; }
/// <summary> /// 增加转换条件 /// </summary> /// <param name="state">状态名</param> /// <param name="transformSate">转换状态名</param> /// <param name="param">条件参数名</param> public void AddTransition(string state, string desState, string param) { animatorController = m_animator.runtimeAnimatorController as AnimatorController; animStM = animatorController.layers[0].stateMachine; AnimatorState animSt = GetState(state); if (animSt.transitions.Length != 0) { foreach (AnimatorStateTransition animStTrans in animSt.transitions) { if (animStTrans.destinationState.name == GetState(desState).name) { Debug.LogError("此转换:" + state + " to " + desState + "已存在"); return; } } } AnimatorStateTransition trans = animSt.AddTransition(GetState(desState)); animatorController.AddParameter(param, AnimatorControllerParameterType.Bool); trans.AddCondition(AnimatorConditionMode.If, 0, param); }
void AddAnimation() { animationController.AddParameter(triggerName, AnimatorControllerParameterType.Trigger); //Top Layer for (int i = 0; i < 2; i++) { //Create New State var stateMachine = animationController.layers[i].stateMachine; string stateName = triggerName + " State"; AnimatorState newState = stateMachine.AddState(stateName); newState.motion = dynamicAnimation; //To var anyToActionTransition = stateMachine.AddAnyStateTransition(newState); anyToActionTransition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, triggerName); //From newState.AddTransition(stateMachine.defaultState, true); } }
private AnimatorControllerLayer CreateVolumeLayer(string rootName, string paramName, AnimationClip volumeSet) { AnimatorControllerLayer layer = new AnimatorControllerLayer { name = paramName, defaultWeight = 1, stateMachine = new AnimatorStateMachine() { name = paramName } }; AnimatorStateMachine stateMachine = layer.stateMachine; AnimatorState waitState = stateMachine.AddState("Wait"); AnimatorState toggleState = stateMachine.AddState(paramName); toggleState.timeParameter = paramName; toggleState.timeParameterActive = true; toggleState.motion = volumeSet; waitState.AddTransition(toggleState).AddCondition(AnimatorConditionMode.Greater, 0, paramName); Avatar8Track.CreateAsset(AudioClip, volumeSet, paramName + ".anim"); return(layer); }
static void AddTransition(AnimatorState from, AnimatorState to, bool exitTime) { AnimatorStateTransition transition = from.AddTransition(to, exitTime); AddTransitionParam(from, to, transition); }
public override void OnContinuePressed() { switch (currentStep) { case 1: triggerNames = new string[settings.gestures.Count]; for (int a = 0; a < settings.gestures.Count; a++) { triggerNames[a] = settings.gestures[a] + "_trigger"; } break; case 2: if (newLayerChoice == 0) { for (int l = 0; l < controller.layers.Length; l++) { if (controller.layers[l].name == newLayerName) { controller.RemoveLayer(l); } } controller.AddLayer(newLayerName); layerSelected = controller.layers.Length - 1; if (additive) { controller.layers[layerSelected].blendingMode = AnimatorLayerBlendingMode.Additive; } } // Create Triggers for (int a = 0; a < settings.gestures.Count; a++) { for (int p = 0; p < controller.parameters.Length; p++) { if (controller.parameters[p].name == triggerNames[a]) { controller.RemoveParameter(p); } } controller.AddParameter(triggerNames[a], AnimatorControllerParameterType.Trigger); } AnimatorStateMachine sm = controller.layers[layerSelected].stateMachine; // Create States and transitions AnimatorState defaultState = null; defaultState = sm.AddState("None"); if (newLayerChoice == 0) { sm.defaultState = defaultState; } for (int a = 0; a < settings.gestures.Count; a++) { AnimatorState newState = null; newState = sm.AddState(settings.gestures[a]); newState.motion = component.gestures[a].clip; AnimatorStateTransition transition = null; transition = defaultState.AddTransition(newState); transition.duration = transitionTime; transition.interruptionSource = allowGestureInterrupts ? TransitionInterruptionSource.SourceThenDestination : TransitionInterruptionSource.None; transition.AddCondition(AnimatorConditionMode.If, 0, triggerNames[a]); transition = newState.AddTransition(defaultState); transition.hasExitTime = true; transition.duration = transitionTime; transition.interruptionSource = TransitionInterruptionSource.Destination; component.gestures[a].triggerName = triggerNames[a]; } component.gesturesLayer = layerSelected; break; } }
public static RuntimeAnimatorController Create( SimpleCharacterAnimatorControllerDefinition definition) { AnimatorController animatorController = AnimatorController.CreateAnimatorControllerAtPath(definition.ResulutPath); AnimatorStateMachine stateMachine = animatorController.layers.First().stateMachine; AnimatorState defaultState = stateMachine.AddState("Default"); defaultState.motion = definition.DefaultAnimationClip; AnimatorState pinchState = stateMachine.AddState("Pinch"); pinchState.motion = definition.PinchAnimationClip; AnimatorState hitState = stateMachine.AddState("Hit"); hitState.motion = definition.HitAnimationClip; AnimatorState walkState = stateMachine.AddState("Walk"); walkState.motion = definition.WalkAnimationClip; AnimatorControllerParameter hpRateParameter = new AnimatorControllerParameter { name = "HpRate", defaultFloat = 1.0F, type = AnimatorControllerParameterType.Float }; animatorController.AddParameter(hpRateParameter); stateMachine.defaultState = defaultState; { AnimatorStateTransition transition = new AnimatorStateTransition { destinationState = defaultState, hasExitTime = true, exitTime = 1.0F, duration = 0.0F }; hitState.AddTransition(transition); } { AnimatorStateTransition transition = new AnimatorStateTransition { destinationState = pinchState, hasExitTime = false, duration = 0.0F, }; transition.AddCondition(AnimatorConditionMode.Less, 0.3F, hpRateParameter.name); defaultState.AddTransition(transition); } { AnimatorStateTransition transition = new AnimatorStateTransition { destinationState = defaultState, hasExitTime = false, duration = 0.0F, }; transition.AddCondition(AnimatorConditionMode.Greater, 0.3F, hpRateParameter.name); pinchState.AddTransition(transition); } return(animatorController); }
static void makeOneEBAniCtrlAndFab(EBAniControls controls) { bool isExists = File.Exists(controls.fbxPath); if (!isExists) { Debug.LogWarning(controls.fbxPath + "不存在!!!"); return; } string _fold = Path.GetDirectoryName(controls.fbxPath); string _pathAniCtrl = _fold + Path.DirectorySeparatorChar + controls.name + ".controller"; if (File.Exists(_pathAniCtrl)) { File.Delete(_pathAniCtrl); } //创建animationController文件,保存在Assets路径下 AnimatorController aniController = AnimatorController.CreateAnimatorControllerAtPath(_pathAniCtrl); int lens = 0; // =========== layer begin ============ aniController.RemoveLayer(0); lens = controls.listLayers.Count; Dictionary <string, AvatarMask> mapAvatarMask = new Dictionary <string, AvatarMask> (); AvatarMask mask; for (int i = 0; i < lens; i++) { EBAniLayers tmp = controls.listLayers [i]; aniController.AddLayer(tmp.name); AnimatorControllerLayer aniLayer = aniController.layers [i]; aniLayer.defaultWeight = tmp.weight; if (string.IsNullOrEmpty(tmp.mask)) { continue; } if (mapAvatarMask.ContainsKey(tmp.mask)) { mask = mapAvatarMask [tmp.mask]; } else { if (File.Exists(tmp.mask)) { mask = AssetDatabase.LoadAssetAtPath(tmp.mask, typeof(AvatarMask)) as AvatarMask; mapAvatarMask [tmp.mask] = mask; } else { mask = null; } } if (mask != null) { aniLayer.avatarMask = mask; } } // =========== parameter begin ============ lens = controls.listParameters.Count; for (int i = 0; i < lens; i++) { EBAniParameters tmp = controls.listParameters [i]; aniController.AddParameter(tmp.name, tmp.getPType); } // =========== AnimationClip state begin ============ lens = controls.listState.Count; string _fabName = Path.GetFileName(controls.fbxPath); int _indSuffex = _fabName.LastIndexOf("."); string _fabName2 = _fabName.Substring(0, _indSuffex); string _suffex = _fabName.Substring(_indSuffex + 1); if (controls.isHumanid) { string _pathClip = ""; for (int i = 0; i < lens; i++) { EBAniState _state = controls.listState [i]; if (string.IsNullOrEmpty(_state.actName)) { continue; } _pathClip = _fold + Path.DirectorySeparatorChar + _fabName2 + "@" + _state.actName + "." + _suffex; if (File.Exists(_pathClip)) { UnityEngine.Object[] _objs = AssetDatabase.LoadAllAssetsAtPath(_pathClip); relishipClip(_objs, controls, _state); } } } else { UnityEngine.Object[] _objs = AssetDatabase.LoadAllAssetsAtPath(controls.aniPath); relishipClip(_objs, controls, null); } Dictionary <string, AnimatorState>[] stateDics = new Dictionary <string, AnimatorState> [aniController.layers.Length]; for (int i = 0; i < lens; i++) { EBAniState _state = controls.listState [i]; if (_state.aniClip != null || "None".Equals(_state.name)) { AnimatorControllerLayer aniLayer = aniController.layers [_state.layerIndex]; // .GetLayer (_state.layerIndex); AnimatorStateMachine aniMachine = aniLayer.stateMachine; AnimatorState aniState = aniMachine.AddState(_state.name); if ("None".Equals(_state.name)) { aniMachine.defaultState = aniState; } // BlendTree tree = new BlendTree (); // tree.blendType = BlendTreeType.SimpleDirectional2D; // tree.blendParameter = "Action"; // tree.AddChild(_state.aniClip, new Vector2(0.2f, 0.5f)); // tree.name = "_state.name"; aniState.motion = _state.aniClip; aniState.speed = _state.speed; if (stateDics [_state.layerIndex] == null) { stateDics [_state.layerIndex] = new Dictionary <string, AnimatorState> (); } stateDics[_state.layerIndex].Add(_state.name, aniState); } } //需要先将state添加完成后,才能建立 state之间的关系、 //但这里有个问题,就是怎么判断不同layer的state for (int i = 0, len = controls.listState.Count; i < len; i++) { EBAniState _state = controls.listState [i]; AnimatorControllerLayer aniLayer = aniController.layers [_state.layerIndex]; // .GetLayer (_state.layerIndex); AnimatorStateMachine aniMachine = aniLayer.stateMachine; if (stateDics [_state.layerIndex] [_state.name] == null) { Debug.Log(_state.layerIndex + " " + _state.name + " " + stateDics [_state.layerIndex]); } AnimatorState aniState = stateDics[_state.layerIndex] [_state.name]; AnimatorStateTransition startTransition = null; if (!string.IsNullOrEmpty(_state.enterState)) { if (_state.enterState.Equals("Entry")) { aniMachine.defaultState = aniState; } else if (_state.enterState.Equals("Any")) { startTransition = aniMachine.AddAnyStateTransition(aniState); } else if (stateDics[_state.layerIndex].ContainsKey(_state.enterState)) { startTransition = stateDics[_state.layerIndex][_state.enterState].AddTransition(aniState); } } if (startTransition != null) { startTransition.exitTime = _state.enterExitTime; startTransition.duration = 1 - _state.enterExitTime; //过渡用百分比的形式 startTransition.hasFixedDuration = _state.enterHasFixed; //是否动画播放完才过渡 startTransition.hasExitTime = _state.enterHasExitTime; startTransition.canTransitionToSelf = false; for (int j = 0, jlen = _state.enterBrigdes.Count; j < jlen; j++) { EBAniBrigdes brigde = _state.enterBrigdes [j]; startTransition.AddCondition(brigde.getTMode, brigde.getTVal, brigde.ebPars.name); } } AnimatorStateTransition endTransition = null; if (!string.IsNullOrEmpty(_state.endState) && stateDics[_state.layerIndex].ContainsKey(_state.endState)) { endTransition = aniState.AddTransition(stateDics[_state.layerIndex][_state.endState]); } if (endTransition != null) { endTransition.exitTime = _state.endExitTime; endTransition.duration = 1 - _state.endExitTime; //过渡用百分比的形式 endTransition.hasFixedDuration = _state.endHasFixed; //是否动画播放完才过渡 endTransition.hasExitTime = _state.endHasExitTime; endTransition.canTransitionToSelf = false; for (int j = 0, jlen = _state.endBrigdes.Count; j < jlen; j++) { EBAniBrigdes brigde = _state.endBrigdes [j]; endTransition.AddCondition(brigde.getTMode, brigde.getTVal, brigde.ebPars.name); } } } // =========== 生成prefab 并绑定 animator controller ============ string _foldFab = Path.GetDirectoryName(controls.prefabPath); if (!Directory.Exists(_foldFab)) { Directory.CreateDirectory(_foldFab); } UnityEngine.GameObject gobjFab; UnityEngine.GameObject gobjFBX = AssetDatabase.LoadAssetAtPath(controls.fbxPath, typeof(UnityEngine.GameObject)) as GameObject; if (File.Exists(controls.prefabPath)) { // File.Delete (controls.prefabPath); gobjFab = AssetDatabase.LoadAssetAtPath(controls.prefabPath, typeof(UnityEngine.GameObject)) as GameObject; } else { gobjFab = GameObject.Instantiate(gobjFBX) as GameObject; } Animator aniFab = gobjFab.GetComponent <Animator> (); aniFab.runtimeAnimatorController = aniController; aniFab.applyRootMotion = false; UnityEngine.GameObject gobjParent; if (controls.isAddParent) { gobjParent = new GameObject(gobjFab.name); gobjFab.transform.parent = gobjParent.transform; } else { gobjParent = gobjFab; } if (!File.Exists(controls.prefabPath)) { PrefabUtility.CreatePrefab(controls.prefabPath, gobjParent); EditorUtility.SetDirty(gobjParent); GameObject.DestroyImmediate(gobjParent); } }
void CreateANewController() { var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/" + animationControllerName + ".controller"); controller.AddParameter("Forwards", AnimatorControllerParameterType.Float); controller.AddParameter("Horizontal", AnimatorControllerParameterType.Float); controller.AddParameter("Crouching", AnimatorControllerParameterType.Bool); controller.AddParameter("Speed", AnimatorControllerParameterType.Float); controller.AddParameter("Engaging", AnimatorControllerParameterType.Bool); controller.AddParameter("Melee", AnimatorControllerParameterType.Trigger); controller.AddParameter("Reloading", AnimatorControllerParameterType.Trigger); controller.AddParameter("Fire", AnimatorControllerParameterType.Trigger); controller.AddParameter("Sprinting", AnimatorControllerParameterType.Bool); controller.AddParameter("DodgeRight", AnimatorControllerParameterType.Trigger); controller.AddParameter("DodgeLeft", AnimatorControllerParameterType.Trigger); controller.AddParameter("Leap", AnimatorControllerParameterType.Trigger); controller.AddParameter("Vault", AnimatorControllerParameterType.Trigger); controller.AddParameter("Stagger", AnimatorControllerParameterType.Trigger); //LAYER 1/////////////////////////////////////////// //Add Outer States var baseStateMachine = controller.layers[0].stateMachine; //Set Move Tree //new BlendTree(); BlendTree moveTree = new BlendTree(); AnimatorState moveState = controller.CreateBlendTreeInController("Move", out moveTree, 0); //Add Transitions AnimatorState baseCrouching = null; if (crouchingAnimation) { baseCrouching = baseStateMachine.AddState("Crouch"); baseCrouching.motion = crouchingAnimation; //Move var moveToCrouchTranistion = moveState.AddTransition(baseCrouching, false); moveToCrouchTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Crouching"); var crouchToMoveTranistion = baseCrouching.AddTransition(moveState, false); crouchToMoveTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.IfNot, 0.25f, "Crouching"); } if (fullBodyMeleeAnimation && meleeAnimation) { var baseMelee = baseStateMachine.AddState("Melee"); baseMelee.motion = meleeAnimation; //Melee if (baseCrouching != null) { var crouchToMeleeTranistion = baseCrouching.AddTransition(baseMelee, false); crouchToMeleeTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Melee"); } //Move var moveToMeleeTranistion = moveState.AddTransition(baseMelee, false); moveToMeleeTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Melee"); baseMelee.AddTransition(moveState, true); } // if (sprintingAnimation) { var baseSprint = baseStateMachine.AddState("Sprint"); baseSprint.motion = sprintingAnimation; //Move var moveToSprintTranistion = moveState.AddTransition(baseSprint, false); moveToSprintTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Sprinting"); var sprintToMoveTranistion = baseSprint.AddTransition(moveState, false); sprintToMoveTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.IfNot, 0.25f, "Sprinting"); } //Set Parameters moveTree.blendType = BlendTreeType.FreeformDirectional2D; moveTree.blendParameter = "Horizontal"; moveTree.blendParameterY = "Forwards"; //Add Animations float walkThreshold = 0.5f; float runThreshold = 1.0f; moveTree.AddChild(idleAnimation, new Vector2(0.0f, 0.0f)); moveTree.AddChild(runForwardsAnimation, new Vector2(0.0f, runThreshold)); if (walkForwardsAnimation) { moveTree.AddChild(walkForwardsAnimation, new Vector2(0.0f, walkThreshold)); } moveTree.AddChild(runBackwardsAnimation, new Vector2(0.0f, -runThreshold)); if (walkBackwardsAnimation) { moveTree.AddChild(walkBackwardsAnimation, new Vector2(0.0f, -walkThreshold)); } moveTree.AddChild(runRightAnimation, new Vector2(runThreshold, 0.0f)); if (walkRightAnimation) { moveTree.AddChild(walkRightAnimation, new Vector2(walkThreshold, 0.0f)); } moveTree.AddChild(runLeftAnimation, new Vector2(-runThreshold, 0.0f)); if (walkLeftAnimation) { moveTree.AddChild(walkLeftAnimation, new Vector2(-walkThreshold, 0.0f)); } if (walkForwardRightsAnimation) { moveTree.AddChild(walkForwardRightsAnimation, new Vector2(walkThreshold, walkThreshold)); } if (walkForwardLeftAnimation) { moveTree.AddChild(walkForwardLeftAnimation, new Vector2(-walkThreshold, walkThreshold)); } if (walkBackwardsRightAnimation) { moveTree.AddChild(walkBackwardsRightAnimation, new Vector2(walkThreshold, -walkThreshold)); } if (walkBackwardsLeftAnimation) { moveTree.AddChild(walkBackwardsLeftAnimation, new Vector2(-walkThreshold, -walkThreshold)); } if (runForwardRightsAnimation) { moveTree.AddChild(runForwardRightsAnimation, new Vector2(runThreshold, runThreshold)); } if (runForwardLeftAnimation) { moveTree.AddChild(runForwardLeftAnimation, new Vector2(-runThreshold, runThreshold)); } if (runBackwardsRightAnimation) { moveTree.AddChild(runBackwardsRightAnimation, new Vector2(runThreshold, -runThreshold)); } if (runBackwardsLeftAnimation) { moveTree.AddChild(runBackwardsLeftAnimation, new Vector2(-runThreshold, -runThreshold)); } if (dodgeLeftAnimation) { AnimatorState leftDB = baseStateMachine.AddState("DodgeLeft"); leftDB.motion = dodgeLeftAnimation; var anyToLeftDTranistion = baseStateMachine.AddAnyStateTransition(leftDB); anyToLeftDTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "DodgeLeft"); leftDB.AddTransition(moveState, true); } if (dodgeRightAnimation) { AnimatorState rightDB = baseStateMachine.AddState("DodgeRight"); rightDB.motion = dodgeRightAnimation; var anyToRightDTranistion = baseStateMachine.AddAnyStateTransition(rightDB); anyToRightDTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "DodgeRight"); rightDB.AddTransition(moveState, true); } if (leapAnimation) { AnimatorState leapB = baseStateMachine.AddState("Leap"); leapB.motion = leapAnimation; var anyToLeapBTranistion = baseStateMachine.AddAnyStateTransition(leapB); anyToLeapBTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Leap"); leapB.AddTransition(moveState, true); } if (vaultAnimation) { AnimatorState vaultB = baseStateMachine.AddState("Vault"); vaultB.motion = vaultAnimation; var anyToVaultBTranistion = baseStateMachine.AddAnyStateTransition(vaultB); anyToVaultBTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Vault"); vaultB.AddTransition(moveState, true); } if (staggerAnimation) { AnimatorState staggerB = baseStateMachine.AddState("Stagger"); staggerB.motion = staggerAnimation; var anyToStaggerBTranistion = baseStateMachine.AddAnyStateTransition(staggerB); anyToStaggerBTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Stagger"); staggerB.AddTransition(moveState, true); } //////////////////////////////////////////////////// //Layer 2 //////////////////////////////////////////////////// controller.AddLayer("UpperBody"); var upperStateMachine = controller.layers[1].stateMachine; var upperAim = upperStateMachine.AddState("Aim"); upperAim.motion = aimingAnimation; BlendTree idleUpperTree = new BlendTree(); AnimatorState upperIdle = controller.CreateBlendTreeInController("Idle", out idleUpperTree, 1); idleUpperTree.blendParameter = "Speed"; idleUpperTree.AddChild(idleUpperAnim, 0.0f); if (walkUpperAnim) { idleUpperTree.AddChild(walkUpperAnim, 0.5f); } if (runUpperAnim) { idleUpperTree.AddChild(runUpperAnim, 1.0f); } //Idle Transitions var idleToAim = upperIdle.AddTransition(upperAim, false); idleToAim.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Engaging"); var aimToidle = upperAim.AddTransition(upperIdle, false); aimToidle.AddCondition(UnityEditor.Animations.AnimatorConditionMode.IfNot, 0.25f, "Engaging"); if (dodgeLeftAnimation) { AnimatorState leftD = upperStateMachine.AddState("DodgeLeft"); leftD.motion = dodgeLeftAnimation; var anyToLeftDTranistion = upperStateMachine.AddAnyStateTransition(leftD); anyToLeftDTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "DodgeLeft"); leftD.AddTransition(upperAim, true); } if (dodgeRightAnimation) { AnimatorState rightD = upperStateMachine.AddState("DodgeRight"); rightD.motion = dodgeRightAnimation; var anyToRightDTranistion = upperStateMachine.AddAnyStateTransition(rightD); anyToRightDTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "DodgeRight"); rightD.AddTransition(upperAim, true); } if (leapAnimation) { AnimatorState leapU = upperStateMachine.AddState("Leap"); leapU.motion = leapAnimation; var anyToLeapUTranistion = upperStateMachine.AddAnyStateTransition(leapU); anyToLeapUTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Leap"); leapU.AddTransition(upperAim, true); } if (vaultAnimation) { AnimatorState vaultU = upperStateMachine.AddState("Vault"); vaultU.motion = vaultAnimation; var anyToVaultUTranistion = upperStateMachine.AddAnyStateTransition(vaultU); anyToVaultUTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Vault"); vaultU.AddTransition(upperAim, true); } if (staggerAnimation) { AnimatorState staggerU = upperStateMachine.AddState("Stagger"); staggerU.motion = staggerAnimation; var anyToStaggerUTranistion = upperStateMachine.AddAnyStateTransition(staggerU); anyToStaggerUTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Stagger"); staggerU.AddTransition(upperAim, true); } //Melee if (meleeAnimation) { AnimatorState upperMelee = upperStateMachine.AddState("Melee"); upperMelee.motion = meleeAnimation; var aimToMeleeTranistion = upperAim.AddTransition(upperMelee, false); aimToMeleeTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Melee"); upperMelee.AddTransition(upperAim, true); } if (sprintingAnimation) { var upperSprint = upperStateMachine.AddState("Sprint"); upperSprint.motion = sprintingAnimation; //Move var aimToSprintTranistion = upperAim.AddTransition(upperSprint, false); aimToSprintTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Sprinting"); var sprintToAimTranistion = upperSprint.AddTransition(upperAim, false); sprintToAimTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.IfNot, 0.25f, "Sprinting"); } //Reload if (reloadAnimation) { AnimatorState reloadAnim = upperStateMachine.AddState("Reload"); reloadAnim.motion = reloadAnimation; var aimToReloadTranistion = upperAim.AddTransition(reloadAnim, false); aimToReloadTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Reloading"); reloadAnim.AddTransition(upperAim, true); } //Fire if (fireAnimation) { Debug.Log("Tactical"); AnimatorState fireAnim = upperStateMachine.AddState("Fire"); fireAnim.motion = fireAnimation; var aimToFireTranistion = upperAim.AddTransition(fireAnim, false); aimToFireTranistion.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0.25f, "Fire"); fireAnim.AddTransition(upperAim, true); } }
void CreateController() { if (m_Controller == null && m_AvatarPreview != null && m_AvatarPreview.Animator != null && m_RefTransition != null) { // controller m_LayerIndex = 0; m_Controller = new AnimatorController(); m_Controller.pushUndo = false; m_Controller.hideFlags = HideFlags.HideAndDontSave; m_Controller.AddLayer("preview"); bool isDefaultMask = true; if (m_LayerMask != null) { for (AvatarMaskBodyPart i = 0; i < AvatarMaskBodyPart.LastBodyPart && isDefaultMask; i++) { if (!m_LayerMask.GetHumanoidBodyPartActive(i)) { isDefaultMask = false; } } if (!isDefaultMask) { m_Controller.AddLayer("Additionnal"); m_LayerIndex++; AnimatorControllerLayer[] layers = m_Controller.layers; layers[m_LayerIndex].avatarMask = m_LayerMask; m_Controller.layers = layers; } } m_StateMachine = m_Controller.layers[m_LayerIndex].stateMachine; m_StateMachine.pushUndo = false; m_StateMachine.hideFlags = HideFlags.HideAndDontSave; m_SrcMotion = m_RefSrcState.motion; m_DstMotion = m_RefDstState.motion; /// Add parameters m_ParameterMinMax.Clear(); if (m_SrcMotion && m_SrcMotion is BlendTree) { BlendTree leftBlendTree = m_SrcMotion as BlendTree; for (int i = 0; i < leftBlendTree.recursiveBlendParameterCount; i++) { string blendValueName = leftBlendTree.GetRecursiveBlendParameter(i); if (m_Controller.IndexOfParameter(blendValueName) == -1) { m_Controller.AddParameter(blendValueName, AnimatorControllerParameterType.Float); m_ParameterMinMax.Add(new Vector2(leftBlendTree.GetRecursiveBlendParameterMin(i), leftBlendTree.GetRecursiveBlendParameterMax(i))); } } } if (m_DstMotion && m_DstMotion is BlendTree) { BlendTree rightBlendTree = m_DstMotion as BlendTree; for (int i = 0; i < rightBlendTree.recursiveBlendParameterCount; i++) { string blendValueName = rightBlendTree.GetRecursiveBlendParameter(i); int parameterIndex = m_Controller.IndexOfParameter(blendValueName); if (parameterIndex == -1) { m_Controller.AddParameter(blendValueName, AnimatorControllerParameterType.Float); m_ParameterMinMax.Add(new Vector2(rightBlendTree.GetRecursiveBlendParameterMin(i), rightBlendTree.GetRecursiveBlendParameterMax(i))); } else { m_ParameterMinMax[parameterIndex] = new Vector2(Mathf.Min(rightBlendTree.GetRecursiveBlendParameterMin(i), m_ParameterMinMax[parameterIndex][0]), Mathf.Max(rightBlendTree.GetRecursiveBlendParameterMax(i), m_ParameterMinMax[parameterIndex][1])); } } } // states m_SrcState = m_StateMachine.AddState(m_RefSrcState.name); m_SrcState.pushUndo = false; m_SrcState.hideFlags = HideFlags.HideAndDontSave; m_DstState = m_StateMachine.AddState(m_RefDstState.name); m_DstState.pushUndo = false; m_DstState.hideFlags = HideFlags.HideAndDontSave; CopyStateForPreview(m_RefSrcState, ref m_SrcState); CopyStateForPreview(m_RefDstState, ref m_DstState); // transition m_Transition = m_SrcState.AddTransition(m_DstState, true); m_Transition.pushUndo = false; m_Transition.hideFlags = HideFlags.DontSave; CopyTransitionForPreview(m_RefTransition, ref m_Transition); DisableIKOnFeetIfNeeded(); AnimatorController.SetAnimatorController(m_AvatarPreview.Animator, m_Controller); m_Controller.OnAnimatorControllerDirty += ControllerDirty; } }