TaskVerifyBuildResult_SBP.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Linq;
  3. using System.IO;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEditor;
  7. using UnityEngine;
  8. using UnityEditor.Build.Pipeline.Interfaces;
  9. namespace YooAsset.Editor
  10. {
  11. [TaskAttribute("验证构建结果")]
  12. public class TaskVerifyBuildResult_SBP : IBuildTask
  13. {
  14. void IBuildTask.Run(BuildContext context)
  15. {
  16. var buildParametersContext = context.GetContextObject<BuildParametersContext>();
  17. // 模拟构建模式下跳过验证
  18. if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
  19. return;
  20. // 验证构建结果
  21. if (buildParametersContext.Parameters.VerifyBuildingResult)
  22. {
  23. var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
  24. VerifyingBuildingResult(context, buildResultContext.Results);
  25. }
  26. }
  27. /// <summary>
  28. /// 验证构建结果
  29. /// </summary>
  30. private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults)
  31. {
  32. var buildParameters = context.GetContextObject<BuildParametersContext>();
  33. var buildMapContext = context.GetContextObject<BuildMapContext>();
  34. List<string> buildedBundles = buildResults.BundleInfos.Keys.ToList();
  35. // 1. 过滤掉原生Bundle
  36. List<string> expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList();
  37. // 2. 验证Bundle
  38. List<string> exceptBundleList1 = buildedBundles.Except(expectBundles).ToList();
  39. if (exceptBundleList1.Count > 0)
  40. {
  41. foreach (var exceptBundle in exceptBundleList1)
  42. {
  43. Debug.LogWarning($"差异资源包: {exceptBundle}");
  44. }
  45. throw new System.Exception("存在差异资源包!请查看警告信息!");
  46. }
  47. // 3. 验证Bundle
  48. List<string> exceptBundleList2 = expectBundles.Except(buildedBundles).ToList();
  49. if (exceptBundleList2.Count > 0)
  50. {
  51. foreach (var exceptBundle in exceptBundleList2)
  52. {
  53. Debug.LogWarning($"差异资源包: {exceptBundle}");
  54. }
  55. throw new System.Exception("存在差异资源包!请查看警告信息!");
  56. }
  57. BuildRunner.Log("构建结果验证成功!");
  58. }
  59. }
  60. }