Esempio n. 1
0
        // ================================================================================
        //  create animator controllers
        // --------------------------------------------------------------------------------

        private void CreateAnimatorController(ImportedAnimationSheet animations, AnimationImportJob job)
        {
            AnimatorController controller;

            string directory = sharedData.animationControllersTargetLocation.GetAndEnsureTargetDirectory(job.assetPath);

            // check if controller already exists; use this to not loose any references to this in other assets
            string pathForAnimatorController;

            if (sharedData.namingScheme == NamingScheme.ItsName)
            {
                pathForAnimatorController = $"{directory}/animatorController.controller";
            }
            else
            {
                pathForAnimatorController = $"{directory}/{animations.name}.controller";
            }
            controller = AssetDatabase.LoadAssetAtPath <AnimatorController>(pathForAnimatorController);

            if (controller == null)
            {
                // create a new controller and place every animation as a state on the first layer
                controller = AnimatorController.CreateAnimatorControllerAtPath(pathForAnimatorController);
                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();
        }
Esempio n. 2
0
        // ================================================================================
        //  create animator controllers
        // --------------------------------------------------------------------------------

        private void CreateAnimatorController(ImportedAnimationSheet animations)
        {
            string directory = SharedData.AnimationControllersTargetLocation.GetAndEnsureTargetDirectory(animations.AssetDirectory);

            // check if controller already exists; use this to not loose any references to this in other assets
            string pathForAnimatorController = directory + "/" + animations.Name + ".controller";
            var    controller = AssetDatabase.LoadAssetAtPath <AnimatorController>(pathForAnimatorController);

            if (controller == null)
            {
                // create a new controller and place every animation as a state on the first layer
                controller = AnimatorController.CreateAnimatorControllerAtPath(pathForAnimatorController);
                controller.AddLayer("Default");

                foreach (var animation in animations.Animations)
                {
                    if (animation.IsCategory)
                    {
                        continue;
                    }
                    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();
        }
Esempio n. 3
0
        public void CreateAnimatorController(ImportedAnimationSheet animations)
        {
            AnimatorController controller;

            // check if controller already exists; use this to not loose any references to this in other assets
            string pathForAnimatorController = animations.basePath + "/" + animations.name + ".controller";

            controller = AssetDatabase.LoadAssetAtPath <AnimatorController>(pathForAnimatorController);

            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();
        }