using System; using System.Linq; using System.IO; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace YooAsset.Editor { public class TaskVerifyBuildResult_BBP : IBuildTask { void IBuildTask.Run(BuildContext context) { var buildParametersContext = context.GetContextObject(); var buildParameters = buildParametersContext.Parameters as BuiltinBuildParameters; // 验证构建结果 if (buildParameters.VerifyBuildingResult) { var buildResultContext = context.GetContextObject(); VerifyingBuildingResult(context, buildResultContext.UnityManifest); } } /// /// 验证构建结果 /// private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest) { var buildMapContext = context.GetContextObject(); string[] unityBuildContent = unityManifest.GetAllAssetBundles(); // 1. 计划内容 string[] planningContent = buildMapContext.Collection.Select(t => t.BundleName).ToArray(); // 2. 验证差异 List exceptBundleList1 = unityBuildContent.Except(planningContent).ToList(); if (exceptBundleList1.Count > 0) { foreach (var exceptBundle in exceptBundleList1) { string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}"); BuildLogger.Warning(warning); } string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !"); throw new Exception(exception); } // 3. 验证差异 List exceptBundleList2 = planningContent.Except(unityBuildContent).ToList(); if (exceptBundleList2.Count > 0) { foreach (var exceptBundle in exceptBundleList2) { string warning = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildBundle, $"Found unintended build bundle : {exceptBundle}"); BuildLogger.Warning(warning); } string exception = BuildLogger.GetErrorMessage(ErrorCode.UnintendedBuildResult, $"Unintended build, See the detailed warnings !"); throw new Exception(exception); } BuildLogger.Log("Build results verify success!"); } } }