美文网首页
进阶篇-将Animation Clip嵌入到Animation

进阶篇-将Animation Clip嵌入到Animation

作者: 老汪032588 | 来源:发表于2019-08-01 15:07 被阅读0次

通常我们做动画的时候是这样的

嵌入后是这样的

将代码放到工程里面,对着Control点右键,出现AutoAdd AnimClips in Control,自动把同层所有的AnimClip嵌入到Control里面,同时也会删除这些AnimClips,所以。。。注意备份。

AutoAddAnimClips.cs

代码如下:

using UnityEngine;

using UnityEditor;

public class AutoAddAnimClips : MonoBehaviour

{

    [MenuItem("Assets/AutoAdd AnimClips in Controller")]

    static public void AutoaddAnimClips()

    {

        UnityEditor.Animations.AnimatorController anim_controller = null;

        AnimationClip[] clips = null;

        if (Selection.activeObject.GetType() == typeof(UnityEditor.Animations.AnimatorController))

        {

            anim_controller = (UnityEditor.Animations.AnimatorController)Selection.activeObject;

            clips = anim_controller.animationClips;

            if (anim_controller != null && clips.Length > 0)

            {

                foreach (AnimationClip ac in clips)

                {

                    var acAssetPath = AssetDatabase.GetAssetPath(ac);

                    // Check if this ac is not in the controller

                    if (acAssetPath.EndsWith(".anim"))

                    {

                        var new_ac = Object.Instantiate(ac) as AnimationClip;

                        new_ac.name = ac.name;

                        AssetDatabase.AddObjectToAsset(new_ac, anim_controller);

                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(new_ac));

                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(ac));

                    }

                }

                Debug.Log("<color=orange>Added " + clips.Length.ToString() + " clips to controller: </color><color=yellow>" + anim_controller.name + "</color>");

            }

            else

            {

                Debug.Log("<color=red>Nothing done. Select a controller that has anim clips to nest.</color>");

            }

        }

    }

}

相关文章

网友评论

      本文标题:进阶篇-将Animation Clip嵌入到Animation

      本文链接:https://www.haomeiwen.com/subject/hcoqdctx.html