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 PreAssetBuild() { Debug.Log("------------------------------OnPreAssetBuild------------------------------"); // 检测构建平台是否合法 if (BuildTarget == BuildTarget.NoTarget) { throw new Exception("[BuildPatch] 请选择目标平台"); } // 检测构建版本是否合法 if (EditorTools.IsNumber(BuildVersion.ToString()) == false) { throw new Exception($"[BuildPatch] 版本号格式非法:{BuildVersion}"); } if (BuildVersion < 0) { throw new Exception("[BuildPatch] 请先设置版本号"); } // 检测输出目录是否为空 if (string.IsNullOrEmpty(OutputPath)) { throw new Exception("[BuildPatch] 输出目录不能为空"); } // 检测补丁包是否已经存在 string packageFolderPath = GetPackageFolderPath(); if (Directory.Exists(packageFolderPath)) { throw new Exception($"[BuildPatch] 补丁包已经存在:{packageFolderPath}"); } // 如果是强制重建 if (IsForceRebuild) { // 删除总目录 string parentPath = $"{_outputRoot}/{BuildTarget}"; if (Directory.Exists(parentPath)) { Directory.Delete(parentPath, true); Log($"删除平台总目录:{parentPath}"); } } // 如果输出目录不存在 if (Directory.Exists(OutputPath) == false) { Directory.CreateDirectory(OutputPath); Log($"创建输出目录:{OutputPath}"); } }