Unity5.3 AssetBundleName批量赋值

本文介绍了一个用于Unity5.x的编辑器脚本,该脚本可以批量修改资源依赖的AssetBundle名称,并实现资源及其依赖项的自动打包。通过此工具,可以简化AssetBundle打包流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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");

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TxNet.Ltd.

你的赞同是对我的鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值