/// <summary> /// 生成所有资源 /// </summary> /// <param name="outputPath"></param> /// <param name="platform"></param> /// <param name="target"></param> static public void GenAllAssets(string outputPath, RuntimePlatform platform, BuildTarget target) { var _outputPath = Path.Combine(outputPath, BDApplication.GetPlatformPath(platform)); // + "/" + ; if (Directory.Exists(_outputPath)) { Directory.Delete(_outputPath, true); } _outputPath = null; //1.打包资源 try { //1.搜集keywork ShaderCollection.GenShaderVariant(); //2.打包模式 var config = BDFrameEditorConfigHelper.EditorConfig.AssetConfig; AssetBundleEditorToolsV2.GenAssetBundle(outputPath, platform, target, BuildAssetBundleOptions.ChunkBasedCompression, config.IsUseHashName, config.AESCode); } catch (Exception e) { Debug.LogError(e.Message); return; } //2.编译脚本 try { EditorWindow_ScriptBuildDll.RoslynBuild(outputPath, platform, ScriptBuildTools.BuildMode.Release); } catch (Exception e) { Debug.LogError(e.Message); return; } //3.打包表格 try { Excel2SQLiteTools.ALLExcel2SQLite(outputPath, platform); } catch (Exception e) { Debug.LogError(e.Message); } }
/// <summary> /// 构建所有资源 /// </summary> /// <param name="platform">平台</param> /// <param name="outputPath">输出目录</param> /// <param name="setNewVersionNum">新版本号</param> static public void BuildAllAssets(RuntimePlatform platform, string outputPath, string setNewVersionNum = null) { var newVersionNum = ""; //触发事件 var lastPackageBuildInfo = GlobalAssetsHelper.GetPackageBuildInfo(outputPath, platform); var lastVersionNum = lastPackageBuildInfo.Version; //没有指定版本号,则需要触发版本号的实现逻辑 if (string.IsNullOrEmpty(setNewVersionNum)) { BDFrameworkPipelineHelper.OnBeginBuildAllAssets(platform, outputPath, lastVersionNum, out newVersionNum); } //项目没有实现提供新的版本号,则内部提供一个版本号 if (string.IsNullOrEmpty(newVersionNum) || lastVersionNum == newVersionNum) { //没指定版本号 if (string.IsNullOrEmpty(setNewVersionNum)) { newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, add: 1); } //指定版本号 else { newVersionNum = VersionNumHelper.AddVersionNum(lastVersionNum, setNewVersionNum); } } //开始构建资源 var _outputPath = Path.Combine(outputPath, BApplication.GetPlatformPath(platform)); if (!Directory.Exists(_outputPath)) { Directory.CreateDirectory(_outputPath); } //1.编译脚本 try { EditorWindow_ScriptBuildDll.RoslynBuild(outputPath, platform, ScriptBuildTools.BuildMode.Release); } catch (Exception e) { Debug.LogError(e.Message); } //2.打包表格 try { Excel2SQLiteTools.AllExcel2SQLite(outputPath, platform); } catch (Exception e) { Debug.LogError(e.Message); } //3.打包资源 try { //var config = BDEditorApplication.BDFrameWorkFrameEditorSetting.BuildAssetBundle; AssetBundleEditorToolsV2.GenAssetBundle(outputPath, platform); } catch (Exception e) { Debug.LogError(e.Message); } //4.生成母包资源信息 GlobalAssetsHelper.GenBasePackageAssetBuildInfo(outputPath, platform, version: newVersionNum); //5.生成本地Assets.info配置 //这个必须最后生成!!!! //这个必须最后生成!!!! //这个必须最后生成!!!! var allServerAssetItemList = PublishPipelineTools.GetAssetItemList(outputPath, platform); var csv = CsvSerializer.SerializeToString(allServerAssetItemList); var assetsInfoPath = BResources.GetAssetsInfoPath(outputPath, platform); FileHelper.WriteAllText(assetsInfoPath, csv); // Debug.Log($"<color=yellow>{ BApplication.GetPlatformPath(platform)} - 旧版本:{lastPackageBuildInfo.Version} 新版本号:{newVersionNum} </color> "); //完成回调通知 BDFrameworkPipelineHelper.OnEndBuildAllAssets(platform, outputPath, newVersionNum); }
/// <summary> /// 获取AssetItem信息,这里是所有的资源 /// </summary> /// <param name="assetsRootPath"></param> /// <returns></returns> static public List <AssetItem> GetAssetItemList(string assetsRootPath, RuntimePlatform platform) { Debug.Log($"<color=red>------>生成服务器配置:{platform}</color>"); //黑名单 List <string> blackFileList = new List <string>() { BResources.EDITOR_ART_ASSET_BUILD_INFO_PATH, BResources.ASSETS_INFO_PATH, BResources.ASSETS_SUB_PACKAGE_CONFIG_PATH, string.Format("{0}/{0}", BResources.ART_ASSET_ROOT_PATH), }; //混淆文件添加黑名单 blackFileList.AddRange(AssetBundleEditorToolsV2.GetMixAssets()); //加载assetbundle配置 assetsRootPath = IPath.Combine(assetsRootPath, BApplication.GetPlatformPath(platform)); var abConfigPath = IPath.Combine(assetsRootPath, BResources.ART_ASSET_CONFIG_PATH); var abTypeConfigPath = IPath.Combine(assetsRootPath, BResources.ART_ASSET_TYPES_PATH); var abConfigLoader = new AssetbundleConfigLoder(); abConfigLoader.Load(abConfigPath, abTypeConfigPath); //生成hash配置 var assets = Directory.GetFiles(assetsRootPath, "*", SearchOption.AllDirectories); int ABCounter = 0; int notABCounter = 1000000; //开始生成hash var serverAssetItemList = new List <AssetItem>(); for (int i = 0; i < assets.Length; i++) { var assetPath = assets[i]; EditorUtility.DisplayProgressBar(" 获取资源hash", string.Format("生成文件hash:{0}/{1}", i, assets.Length), i / assets.Length); var ext = Path.GetExtension(assetPath).ToLower(); //无效数据 if (ext == ".manifest" || ext == ".meta") { continue; } //本地的相对路径 var localPath = assetPath.Replace("\\", "/").Replace(assetsRootPath + "/", ""); //黑名单 var ret = blackFileList.FirstOrDefault((bf) => localPath.Equals(bf, StringComparison.OrdinalIgnoreCase) || Path.GetFileName(localPath).Equals(bf)); if (ret != null) { Debug.Log("【黑名单】剔除:" + ret); continue; } //文件信息 var fileHash = FileHelper.GetMurmurHash3(assetPath); var abPath = Path.GetFileName(assetPath); var assetbundleItem = abConfigLoader.AssetbundleItemList.Find((ab) => ab.AssetBundlePath != null && ab.AssetBundlePath.Equals(abPath)); AssetItem item = null; //文件容量 var fileInfo = new FileInfo(assetPath); float fileSize = (int)((fileInfo.Length / 1024f) * 100f) / 100f; //用ab资源id添加 if (assetbundleItem != null) { if (assetbundleItem.Hash == fileHash) { ABCounter++; //这里使用ab的id,用以分包寻找资源 item = new AssetItem() { Id = assetbundleItem.Id, HashName = fileHash, LocalPath = localPath, FileSize = fileSize }; } else { Debug.LogError("【ServerAssetsItem.Info】错误! AssetBundle hash不匹配!"); } } else { notABCounter++; item = new AssetItem() { Id = notABCounter, HashName = fileHash, LocalPath = localPath, FileSize = fileSize }; } serverAssetItemList.Add(item); //放在最后,避免提前return 占用id } EditorUtility.ClearProgressBar(); //按id排序 serverAssetItemList.Sort((a, b) => { if (a.Id < b.Id) { return(-1); } else { return(1); } }); return(serverAssetItemList); }