using System; using System.Linq; using System.IO; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEditor.Build.Pipeline.Interfaces; namespace YooAsset.Editor { [TaskAttribute("验证构建结果")] public class TaskVerifyBuildResult_SBP : IBuildTask { void IBuildTask.Run(BuildContext context) { var buildParametersContext = context.GetContextObject(); // 模拟构建模式下跳过验证 if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild) return; // 验证构建结果 if (buildParametersContext.Parameters.VerifyBuildingResult) { var buildResultContext = context.GetContextObject(); VerifyingBuildingResult(context, buildResultContext.Results); } } /// /// 验证构建结果 /// private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults) { var buildParameters = context.GetContextObject(); var buildMapContext = context.GetContextObject(); List buildedBundles = buildResults.BundleInfos.Keys.ToList(); // 1. 过滤掉原生Bundle List expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList(); // 2. 验证Bundle List exceptBundleList1 = buildedBundles.Except(expectBundles).ToList(); if (exceptBundleList1.Count > 0) { foreach (var exceptBundle in exceptBundleList1) { Debug.LogWarning($"差异资源包: {exceptBundle}"); } throw new System.Exception("存在差异资源包!请查看警告信息!"); } // 3. 验证Bundle List exceptBundleList2 = expectBundles.Except(buildedBundles).ToList(); if (exceptBundleList2.Count > 0) { foreach (var exceptBundle in exceptBundleList2) { Debug.LogWarning($"差异资源包: {exceptBundle}"); } throw new System.Exception("存在差异资源包!请查看警告信息!"); } BuildRunner.Log("构建结果验证成功!"); } } }