private static UnityEditor.Animations.AnimatorState AddStateTransition(UnityEditor.Animations.AnimatorController animatorController, string path, UnityEditor.Animations.AnimatorControllerLayer layer) { ////根据动画文件读取它的AnimationClip对象 AnimationClip newClip = null; if (File.Exists(path)) { newClip = AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip)) as AnimationClip; } string[] sL = Path.GetFileName(path).Split(".".ToCharArray()); string aName = sL[0]; UnityEngine.AnimatorControllerParameter p = new UnityEngine.AnimatorControllerParameter(); p.type = UnityEngine.AnimatorControllerParameterType.Bool; p.name = aName; p.defaultBool = false; animatorController.AddParameter(p); ////取出动画名子 添加到state里面 UnityEditor.Animations.AnimatorState state = layer.stateMachine.AddState(aName); if (newClip != null) { state.motion = newClip; } return(state); //把state添加在layer里面 //UnityEditor.Animations.AnimatorStateTransition ts = sm.AddAnyStateTransition(state); }
static AnimationClip GenerateTriggerableTransition(string name, UnityEditor.Animations.AnimatorController controller) { var clip = UnityEditor.Animations.AnimatorController.AllocateAnimatorClip(name); AssetDatabase.AddObjectToAsset(clip, controller); var state = controller.AddMotion(clip); controller.AddParameter(name, AnimatorControllerParameterType.Trigger); var stateMachine = controller.layers[0].stateMachine; var transition = stateMachine.AddAnyStateTransition(state); transition.AddCondition(UnityEditor.Animations.AnimatorConditionMode.If, 0, name); // var state = UnityEditor.Animations.AnimatorController.AddAnimationClipToController(controller, clip); //controller.AddParameter(name, AnimatorControllerParameterType.Trigger); //var stateMachine = controller.GetLayer(0).stateMachine; //var transition = stateMachine.AddAnyStateTransition(state); //var condition = transition.GetCondition(0); //condition.mode = TransitionConditionMode.If; //condition.parameter = name; //#endif return(clip); }
public void AddUniqueParameter(Animator animator, string parameterName, AnimatorControllerParameterType type) { if (!HasParameter(animator, parameterName, type) && animator.runtimeAnimatorController != null) { UnityEditor.Animations.AnimatorController animatorInternal = (UnityEditor.Animations.AnimatorController)animator.runtimeAnimatorController; if (!HasParameter(animatorInternal, parameterName, type)) { Debug.Log("Adding the parameter " + parameterName); animatorInternal.AddParameter(parameterName, type); animator.runtimeAnimatorController = animatorInternal; } } }
public void ValidateParameters(AnimatorController controller) { foreach (string keyName in _avaCryptKeyNames) { if (controller.parameters.All(parameter => parameter.name != keyName)) { controller.AddParameter(keyName, AnimatorControllerParameterType.Bool); AssetDatabase.SaveAssets(); Debug.Log($"Adding parameter: {keyName}"); } else { Debug.Log($"Parameter already added: {keyName}"); } } }
private static AnimationClip GenerateTriggerableTransition(string name, UnityEditor.Animations.AnimatorController controller) { // Create the clip var clip = UnityEditor.Animations.AnimatorController.AllocateAnimatorClip(name); AssetDatabase.AddObjectToAsset(clip, controller); // Create a state in the animatior controller for this clip var state = controller.AddMotion(clip); // Add a transition property controller.AddParameter(name, AnimatorControllerParameterType.Trigger); // Add an any state transition var stateMachine = controller.layers[0].stateMachine; var transition = stateMachine.AddAnyStateTransition(state); transition.AddCondition(AnimatorConditionMode.If, 0, name); return(clip); }
public void ValidateParameters(AnimatorController controller) { foreach (string keyName in AvaCryptKeyNames) { if (controller.parameters.All(parameter => parameter.name != keyName)) { controller.AddParameter(keyName, AnimatorControllerParameterType.Float); AssetDatabase.SaveAssets(); Debug.Log($"Adding parameter: {keyName}"); } else { Debug.Log($"Parameter already added: {keyName}"); } } if (controller.parameters.Length > 16) { EditorUtility.DisplayDialog("More than 16 Parameters on Controller.", "VRChat only supports 16 custom parameters, and more than 16 were detected on this controller, which means you probably need to delete some.", "Ok"); } }