Unity AssetBundle自动化打包

六月ゝ 毕业季﹏ 提交于 2020-01-26 06:49:03
    //先批量创建配置Prefab,方便AB包加载后导入场景
    private void CreatePrefab(GameObject obj, string path)
    {
        PrefabUtility.CreatePrefab(path + "/" + obj.name + ".prefab", obj, ReplacePrefabOptions.ConnectToPrefab);
        AssetDatabase.SaveAssets();
    }
    //清理所有AssetBundle名字
    private void ClearAssetBundleName()
    {
        foreach (var abName in AssetDatabase.GetAllAssetBundleNames())
        {
            AssetDatabase.RemoveAssetBundleName(abName, true);
        }
        AssetDatabase.RemoveUnusedAssetBundleNames();
    }
    //设置路径下打包文件AssetBundle名和后缀
    private void SetAssetImport(string Assetpath)
    {
        //获取路径下所有文件及子目录路径
        var paths = Directory.GetFileSystemEntries(Assetpath);
        //遍历筛选导入
        foreach (var path in paths )
        {
            if (Path.GetExtension(path) != ".meta")
            {
                var assetImportPath = path.Replace("\\", "/");
                var assetImport = AssetImporter.GetAtPath(assetImportPath);
                assetImport.assetBundleName = AssetDatabase.LoadAssetAtPath<Object>(assetImportPath).name;
                assetImport.assetBundleVariant = "bundle";
            }
        }
    }
BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
AssetDatabase.Refresh();

在这里插入图片描述

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!