/// <summary> /// 删除无效的AB /// </summary> /// <param name="target"></param> /// <param name="encrypted"></param> /// <param name="newResourcePaths"></param> /// <param name="resRootPath"></param> private static void DeleteInvalidRes(BuildTarget target, bool encrypted, List <string> newResourcePaths, string resRootPath) { //记录将要生成的AB Dictionary <string, bool> filesWillExport = new Dictionary <string, bool>(); for (int i = 0; i < newResourcePaths.Count; i++) { string resPackageName = ResPackHelper.GetResPackageName(newResourcePaths[i], false); string fileName = CommonHelper.GetFileName(resPackageName, false); filesWillExport.Add(fileName, true); } //获取当前输出目录中除了lua的AB // List<FileInfo> allPackeages = GetResPackages(target,encrypted, ResPackHelper.ResType.Res, resRootPath); }
//打包指定文件夹中的资源 public static void ExportRes(BuildTarget target, DirectoryInfo[] dirs, FileInfo[] files, string resRootPath) { //如果输出目录不存在,先创建 //string assetBundleOutputPath = List <AssetBundleBuild> builds = new List <AssetBundleBuild>(); // 递归所有子文件夹 获取全部 AssetBundleBuild 信息 if (dirs != null) { for (int i = 0; i < dirs.Length; i++) { RecGetRecAssetBundleBuilds(dirs[i], builds); } } //获取文件的AssetBundleBuild信息 if (files != null) { for (int i = 0; i < files.Length; i++) { AssetBundleBuild build = new AssetBundleBuild(); string fullName = CommonHelper.StandardizePath(files[i].FullName); build.assetBundleName = ResPackHelper.GetResPackageName(fullName, false) + BuildLuaAB.PLAIN_EXT; Debug.Log("bundleName = " + build.assetBundleName); //截取到Assets build.assetNames = new string[] { fullName.Substring(fullName.IndexOf("Assets" + CommonHelper.separatorChar)) }; builds.Add(build); } } //创建AssetBundles if (builds.Count > 0) { CommonHelper.PathCreate(workPath); var buildManifest = BuildPipeline.BuildAssetBundles(workPath, builds.ToArray(), BuildAssetBundleOptions.DeterministicAssetBundle, target); if (buildManifest == null) { Debug.LogError("Error in build"); } Debug.Log("assetbundle资源打包完成。"); } }
private static void RecGetRecAssetBundleBuilds(DirectoryInfo dirInfo, List <AssetBundleBuild> builds) { //获取该文件内所有资源 List <string> fileNames = new List <string>(); FileInfo[] files = dirInfo.GetFiles(); for (int i = 0; i < files.Length; i++) { //剔除一些后缀文件 if (CommonHelper.IsEndWith(FILE_EXCLUDE_PATTERNS, files[i].Name)) { continue; } //获取文件系统路径 带后缀 string fullName = CommonHelper.StandardizePath(files[i].FullName); Debug.Log("子文件夹 真正的 = " + fullName.Substring(fullName.IndexOf("Assets" + CommonHelper.separatorChar))); //从Assets截取 fileNames.Add(fullName.Substring(fullName.IndexOf("Assets" + CommonHelper.separatorChar))); } //获取build信息 if (fileNames.Count > 0) { AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = ResPackHelper.GetResPackageName(dirInfo.FullName, false) + BuildLuaAB.PLAIN_EXT; build.assetNames = fileNames.ToArray(); builds.Add(build); } //递归子文件夹 DirectoryInfo[] subFolders = dirInfo.GetDirectories(); for (int i = 0; i < subFolders.Length; i++) { RecGetRecAssetBundleBuilds(subFolders[i], builds); } }