static AssetBundleBuild[] GetBuildFileListNew(string buildRoot) { //获取所有固定打包的文件 FileInfo[] files = FilePathTools.getFiles(buildRoot); //List<string> fixedPaths = new List<string>(); List <AssetBundleBuild> buildMap = new List <AssetBundleBuild>(); for (int i = 0; i < files.Length; i++) { //获取相对于asset目录的相对路径 string path = FilePathTools.getRelativePath(files[i].FullName); AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = getAssetBundleNameWithPath(path); build.assetNames = new string[1] { path }; buildMap.Add(build); } Debug.Log("获取所有打包资源完毕:" + buildMap.Count); return(buildMap.ToArray()); }
//获取所有需要打包的文件 static AssetBundleBuild[] getBuildFileList(string buildRoot) { //获取所有固定打包的文件 FileInfo[] files = FilePathTools.getFiles(buildRoot); List <string> fixedPaths = new List <string>(); //固定打包资源(必定被打包的资源) for (int i = 0; i < files.Length; i++) { //获取相对于asset目录的相对路径 fixedPaths.Add(FilePathTools.getRelativePath(files[i].FullName)); } //找出固定打包的文件以及其所有依赖文件 排重 string[] allDependencies = AssetDatabase.GetDependencies(fixedPaths.ToArray(), true); //所有的依赖关系,包括自己并已排重 //寻找固定打包文件和依赖文件的第一层依赖关系并进行依赖计数 Dictionary <string, int> dependenciesCount = new Dictionary <string, int> (); //依赖计数用字典 foreach (string path in allDependencies) { if (Path.GetExtension(path) == ".spriteatlas") { continue; } string[] dependencie = AssetDatabase.GetDependencies(path, false); foreach (string p in dependencie) { if (!dependenciesCount.ContainsKey(p)) { dependenciesCount.Add(p, 1); } else { dependenciesCount[p]++; } } } //将计数器大于1的资源提取出来,剔除掉固定打包的资源 List <AssetBundleBuild> buildMap = new List <AssetBundleBuild> (); List <string> dependenciesPaths = new List <string> ();//被引用次数大于1的依赖资源 需要进行打包 foreach (string key in dependenciesCount.Keys) { int count = dependenciesCount[key]; if (count > 1 && !isFixedBuildAsset(key)) { dependenciesPaths.Add(key); } } //合并固定打包资源和依赖打包资源 List <string> allBuildPaths = new List <string> (fixedPaths); allBuildPaths.AddRange(dependenciesPaths); foreach (string path in allBuildPaths) { //去掉脚本资源 if (Path.GetExtension(path) == ".cs") { continue; } AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = getAssetBundleNameWithPath(path); build.assetNames = new string[1] { path }; buildMap.Add(build); Debug.Log(build.assetBundleName + " | " + build.assetNames[0]); } return(buildMap.ToArray()); }