Unity5.3 AssetBundleName批量赋值

前端之家收集整理的这篇文章主要介绍了Unity5.3 AssetBundleName批量赋值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

    }

猜你在找的设计模式相关文章