void IBuildTask.Run(BuildContext context) { var buildParameters = context.GetContextObject <AssetBundleBuilder.BuildParametersContext>(); var buildOptions = context.GetContextObject <AssetBundleBuilder.BuildOptionsContext>(); // 检测构建平台是否合法 if (buildParameters.BuildTarget == BuildTarget.NoTarget) { throw new Exception("请选择目标平台"); } // 检测构建版本是否合法 if (EditorTools.IsNumber(buildParameters.BuildVersion.ToString()) == false) { throw new Exception($"版本号格式非法:{buildParameters.BuildVersion}"); } if (buildParameters.BuildVersion < 0) { throw new Exception("请先设置版本号"); } // 检测输出目录是否为空 if (string.IsNullOrEmpty(buildParameters.OutputDirectory)) { throw new Exception("输出目录不能为空"); } // 检测补丁包是否已经存在 string packageDirectory = buildParameters.GetPackageDirectory(); if (Directory.Exists(packageDirectory)) { throw new Exception($"补丁包已经存在:{packageDirectory}"); } // 检测资源收集配置文件 if (AssetBundleCollectorSettingData.GetCollecterCount() == 0) { throw new Exception("配置的资源收集路径为空!"); } // 如果是强制重建 if (buildOptions.IsForceRebuild) { // 删除平台总目录 string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}"; if (EditorTools.DeleteDirectory(platformDirectory)) { BuildLogger.Log($"删除平台总目录:{platformDirectory}"); } } // 如果输出目录不存在 if (EditorTools.CreateDirectory(buildParameters.OutputDirectory)) { BuildLogger.Log($"创建输出目录:{buildParameters.OutputDirectory}"); } }
/// <summary> /// 执行构建 /// </summary> public void PostAssetBuild() { Debug.Log("------------------------------OnPostAssetBuild------------------------------"); // 检测工作 if (AssetBundleCollectorSettingData.GetCollecterCount() == 0) { throw new Exception("[BuildPatch] 配置的资源收集路径为空!"); } // 准备工作 List <AssetInfo> buildMap = GetBuildMap(); if (buildMap.Count == 0) { throw new Exception("[BuildPatch] 构建列表不能为空"); } Log($"构建列表里总共有{buildMap.Count}个资源需要构建"); List <AssetBundleBuild> buildInfoList = new List <AssetBundleBuild>(buildMap.Count); for (int i = 0; i < buildMap.Count; i++) { AssetInfo assetInfo = buildMap[i]; AssetBundleBuild buildInfo = new AssetBundleBuild(); buildInfo.assetBundleName = assetInfo.AssetBundleLabel; buildInfo.assetBundleVariant = assetInfo.AssetBundleVariant; buildInfo.assetNames = new string[] { assetInfo.AssetPath }; buildInfoList.Add(buildInfo); } // 开始构建 Log($"开始构建......"); BuildAssetBundleOptions opt = MakeBuildOptions(); AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(OutputDirectory, buildInfoList.ToArray(), opt, BuildTarget); if (unityManifest == null) { throw new Exception("[BuildPatch] 构建过程中发生错误!"); } // 加密资源文件 List <string> encryptList = EncryptFiles(unityManifest); // 1. 检测循环依赖 CheckCycleDepend(unityManifest); // 2. 创建补丁文件 CreatePatchManifestFile(unityManifest, buildMap, encryptList); // 3. 创建说明文件 CreateReadmeFile(unityManifest); // 4. 复制更新文件 CopyUpdateFiles(); Log("构建完成!"); }
void IBuildTask.Run(BuildContext context) { var buildParameters = context.GetContextObject <AssetBundleBuilder.BuildParametersContext>(); // 检测构建平台是否合法 if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget) { throw new Exception("请选择目标平台"); } // 检测构建版本是否合法 if (buildParameters.Parameters.BuildVersion <= 0) { throw new Exception("请先设置版本号"); } // 检测输出目录是否为空 if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory)) { throw new Exception("输出目录不能为空"); } // 检测资源收集配置文件 if (AssetBundleCollectorSettingData.GetCollecterCount() == 0) { throw new Exception("配置的资源收集路径为空"); } // 增量更新时候的必要检测 if (buildParameters.Parameters.IsForceRebuild == false) { // 检测历史版本是否存在 if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false) { throw new Exception("没有发现任何历史版本,请尝试强制重建"); } // 检测构建版本是否合法 int maxPackageVersion = AssetBundleBuilderHelper.GetMaxPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot); if (buildParameters.Parameters.BuildVersion <= maxPackageVersion) { throw new Exception("构建版本不能小于历史版本"); } // 检测补丁包是否已经存在 string packageDirectory = buildParameters.GetPackageDirectory(); if (Directory.Exists(packageDirectory)) { throw new Exception($"补丁包已经存在:{packageDirectory}"); } // 检测内置资源标记是否一致 PatchManifest oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags) { throw new Exception($"增量更新时内置资源标记必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}"); } } // 如果是强制重建 if (buildParameters.Parameters.IsForceRebuild) { // 删除平台总目录 string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}"; if (EditorTools.DeleteDirectory(platformDirectory)) { BuildLogger.Log($"删除平台总目录:{platformDirectory}"); } } // 如果输出目录不存在 if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory)) { BuildLogger.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}"); } }