From b330d26b4f8b83a2339cade65fabdeaca3e1de0b Mon Sep 17 00:00:00 2001 From: hevinci Date: Mon, 6 Mar 2023 19:07:46 +0800 Subject: [PATCH] update asset bundle builder --- .../AssetBundleBuilder/AssetBundleBuilder.cs | 18 ++++----- .../AssetBundleSimulateBuilder.cs | 1 + .../AssetBundleBuilder/BuildParameters.cs | 5 +++ .../BuildSystem/BuildLogger.cs | 39 ++++++++++--------- .../BuildTasks/TaskEncryption.cs | 2 +- .../BuildTasks/TaskVerifyBuildResult.cs | 10 ++--- .../BuildTasks/TaskVerifyBuildResult_SBP.cs | 4 +- 7 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs index 98baacd..c18a5ee 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs @@ -39,12 +39,6 @@ namespace YooAsset.Editor var buildParametersContext = new BuildParametersContext(buildParameters); _buildContext.SetContextObject(buildParametersContext); - // 是否显示LOG - if (buildParameters.BuildMode == EBuildMode.SimulateBuild) - BuildLogger.EnableLog = false; - else - BuildLogger.EnableLog = true; - // 创建构建节点 List pipeline; if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline) @@ -86,19 +80,23 @@ namespace YooAsset.Editor throw new NotImplementedException(); } + // 初始化日志 + BuildLogger.InitLogger(buildParameters.EnableLog); + // 执行构建流程 var buildResult = BuildRunner.Run(pipeline, _buildContext); if (buildResult.Success) { buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory(); - Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !"); + BuildLogger.Log($"{buildParameters.BuildMode} pipeline build succeed !"); } else { - Debug.LogWarning($"{buildParameters.BuildMode} pipeline build failed !"); - Debug.LogError($"Build task failed : {buildResult.FailedTask}"); - Debug.LogError($"Build task error : {buildResult.FailedInfo}"); + BuildLogger.Warning($"{buildParameters.BuildMode} pipeline build failed !"); + BuildLogger.Error($"Build task failed : {buildResult.FailedTask}"); + BuildLogger.Error($"Build task error : {buildResult.FailedInfo}"); } + return buildResult; } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs index e9d4df7..9a89843 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs @@ -18,6 +18,7 @@ namespace YooAsset.Editor buildParameters.BuildMode = EBuildMode.SimulateBuild; buildParameters.PackageName = packageName; buildParameters.PackageVersion = "Simulate"; + buildParameters.EnableLog = false; AssetBundleBuilder builder = new AssetBundleBuilder(); var buildResult = builder.Run(buildParameters); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs index d1ab9d6..3c324c7 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs @@ -67,6 +67,11 @@ namespace YooAsset.Editor public string PackageVersion; + /// + /// 是否显示普通日志 + /// + public bool EnableLog = true; + /// /// 验证构建结果 /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs index daf1b21..2d6026c 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs @@ -1,30 +1,33 @@ - +using System; +using System.IO; +using System.Collections.Generic; +using UnityEngine; + namespace YooAsset.Editor { public static class BuildLogger { - /// - /// 是否启用LOG - /// - public static bool EnableLog = true; + private static bool _enableLog = true; - /// - /// 日志输出 - /// - public static void Log(string info) + public static void InitLogger(bool enableLog) { - if (EnableLog) - { - UnityEngine.Debug.Log(info); - } + _enableLog = enableLog; } - /// - /// 日志输出 - /// - public static void Info(string info) + public static void Log(string message) { - UnityEngine.Debug.Log(info); + if (_enableLog) + { + Debug.Log(message); + } + } + public static void Warning(string message) + { + Debug.LogWarning(message); + } + public static void Error(string message) + { + Debug.LogError(message); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs index a393635..b8494a6 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs @@ -47,7 +47,7 @@ namespace YooAsset.Editor // 注意:原生文件不支持加密 if (bundleInfo.IsRawFile) { - UnityEngine.Debug.LogWarning($"Encryption not support raw file : {bundleInfo.BundleName}"); + BuildLogger.Warning($"Encryption not support raw file : {bundleInfo.BundleName}"); continue; } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs index 5f101ca..9baa5fc 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs @@ -45,7 +45,7 @@ namespace YooAsset.Editor { foreach (var exceptBundle in exceptBundleList1) { - Debug.LogWarning($"差异资源包: {exceptBundle}"); + BuildLogger.Warning($"差异资源包: {exceptBundle}"); } throw new System.Exception("存在差异资源包!请查看警告信息!"); } @@ -56,7 +56,7 @@ namespace YooAsset.Editor { foreach (var exceptBundle in exceptBundleList2) { - Debug.LogWarning($"差异资源包: {exceptBundle}"); + BuildLogger.Warning($"差异资源包: {exceptBundle}"); } throw new System.Exception("存在差异资源包!请查看警告信息!"); } @@ -76,16 +76,16 @@ namespace YooAsset.Editor string[] mapAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle); if (mapAssetPaths.Length != buildedAssetPaths.Length) { - Debug.LogWarning($"构建的Bundle文件内的资源对象数量和预期不匹配 : {buildedBundle}"); + BuildLogger.Warning($"构建的Bundle文件内的资源对象数量和预期不匹配 : {buildedBundle}"); var exceptAssetList1 = mapAssetPaths.Except(buildedAssetPaths).ToList(); foreach (var excpetAsset in exceptAssetList1) { - Debug.LogWarning($"构建失败的资源对象路径为 : {excpetAsset}"); + BuildLogger.Warning($"构建失败的资源对象路径为 : {excpetAsset}"); } var exceptAssetList2 = buildedAssetPaths.Except(mapAssetPaths).ToList(); foreach (var excpetAsset in exceptAssetList2) { - Debug.LogWarning($"构建失败的资源对象路径为 : {excpetAsset}"); + BuildLogger.Warning($"构建失败的资源对象路径为 : {excpetAsset}"); } isPass = false; continue; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs index 80325b4..12ddf89 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs @@ -46,7 +46,7 @@ namespace YooAsset.Editor { foreach (var exceptBundle in exceptBundleList1) { - Debug.LogWarning($"差异资源包: {exceptBundle}"); + BuildLogger.Warning($"差异资源包: {exceptBundle}"); } throw new System.Exception("存在差异资源包!请查看警告信息!"); } @@ -57,7 +57,7 @@ namespace YooAsset.Editor { foreach (var exceptBundle in exceptBundleList2) { - Debug.LogWarning($"差异资源包: {exceptBundle}"); + BuildLogger.Warning($"差异资源包: {exceptBundle}"); } throw new System.Exception("存在差异资源包!请查看警告信息!"); }