进阶篇-将Animation Clip嵌入到Animation Control

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


嵌入后是这样的


将代码放到工程里面,对着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>");

            }

        }

    }

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,216评论 0 13
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,181评论 0 10
  • "use strict";function _classCallCheck(e,t){if(!(e instanc...
    久些阅读 6,182评论 0 2
  • 有的人说了千言万语仍旧无法拉近彼此的距离,有的人坐在对面即使不说话也被互相的气场彼此吸引。磁场相同的人,都会具有某...
    好听的暖阳阅读 1,405评论 4 11
  • 公元猴年马月鸡日,皇上(爱妹觉罗.北京,曾用名北平,燕京,幽州等)昭告天下,朕要找老婆了!立刻有天津,保定,石家庄...
    八千春秋阅读 1,355评论 0 0

友情链接更多精彩内容