private void CreateAnimatorOverrideController(AsepriteAnimationInfo animations) { if (_baseController != null) { AnimatorOverrideController overrideController; // check if override controller already exists; use this to not loose any references to this in other assets string pathForOverrideController = animations.basePath + "/" + animations.name + ".overrideController"; overrideController = AssetDatabase.LoadAssetAtPath <AnimatorOverrideController>(pathForOverrideController); if (overrideController == null) { overrideController = new AnimatorOverrideController(); AssetDatabase.CreateAsset(overrideController, pathForOverrideController); } overrideController.runtimeAnimatorController = _baseController; // set override clips var clipPairs = overrideController.clips; for (int i = 0; i < clipPairs.Length; i++) { string animationName = clipPairs[i].originalClip.name; AnimationClip clip = animations.GetClip(animationName); clipPairs[i].overrideClip = clip; } overrideController.clips = clipPairs; EditorUtility.SetDirty(overrideController); } else { Debug.LogWarning("No Animator Controller found as a base for the Override Controller"); } }
private void CreateAnimatorController(AsepriteAnimationInfo animations) { AnimatorController controller; // check if controller already exists; use this to not loose any references to this in other assets string pathForOverrideController = animations.basePath + "/" + animations.name + ".controller"; controller = AssetDatabase.LoadAssetAtPath <AnimatorController>(pathForOverrideController); if (controller == null) { // create a new controller and place every animation as a state on the first layer controller = AnimatorController.CreateAnimatorControllerAtPath(animations.basePath + "/" + animations.name + ".controller"); controller.AddLayer("Default"); foreach (var animation in animations.animations) { AnimatorState state = controller.layers[0].stateMachine.AddState(animation.name); state.motion = animation.animationClip; } } else { // look at all states on the first layer and replace clip if state has the same name var childStates = controller.layers[0].stateMachine.states; foreach (var childState in childStates) { AnimationClip clip = animations.GetClip(childState.state.name); if (clip != null) { childState.state.motion = clip; } } } EditorUtility.SetDirty(controller); AssetDatabase.SaveAssets(); }