加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Unity5.3 AssetBundleName批量赋值

发布时间:2020-12-13 21:59:00 所属栏目:百科 来源:网络整理
导读:Unity 5.x 的新版AssetBundle打包方式有了很大的变化,所以我写了个编辑器来批量修改资源依赖的AssetbundleName [MenuItem("AssetBundle/BuildAssetBundles")] public static void BuildAssetBundles() { string outputPath = "Assets/bundles"; foreach (Ob

Unity 5.x 的新版AssetBundle打包方式有了很大的变化,所以我写了个编辑器来批量修改资源依赖的AssetbundleName

[MenuItem("AssetBundle/BuildAssetBundles")]
    public static void BuildAssetBundles()
    {
        string outputPath = "Assets/bundles";
        foreach (Object o in Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets))
        {
            //得到指定资源路径
            string path = AssetDatabase.GetAssetPath(o);
            //得到指定资源的bundle名字
            string abName = AssetImporter.GetAtPath(path).assetBundleName;
            //得到指定资源的依赖资源路径
            string[] depends=AssetDatabase.GetDependencies(path);
            //修改所有依赖的bundle名
            foreach (string dp in depends)
            {
                if (dp.EndsWith(".cs") || dp.EndsWith(".js")) continue;

                AssetImporter ai = AssetImporter.GetAtPath(dp);
                ai.assetBundleName = abName;
            }
        }

        
        //生成bundle包的路径
        if (!Directory.Exists(outputPath))
            Directory.CreateDirectory(outputPath);
        //把已经赋值AssetBundleName的Object全部打包到指定目录中
        BuildPipeline.BuildAssetBundles(outputPath);
        AssetDatabase.Refresh();
        Debug.Log("Build AssetBundle Success");

    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读