TaskGetBuildMap.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEditor;
  7. namespace YooAsset.Editor
  8. {
  9. [TaskAttribute("获取资源构建内容")]
  10. public class TaskGetBuildMap : IBuildTask
  11. {
  12. void IBuildTask.Run(BuildContext context)
  13. {
  14. var buildParametersContext = context.GetContextObject<BuildParametersContext>();
  15. var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode);
  16. context.SetContextObject(buildMapContext);
  17. BuildRunner.Log("构建内容准备完毕!");
  18. // 检测构建结果
  19. CheckBuildMapContent(buildMapContext);
  20. }
  21. /// <summary>
  22. /// 检测构建结果
  23. /// </summary>
  24. private void CheckBuildMapContent(BuildMapContext buildMapContext)
  25. {
  26. foreach (var bundleInfo in buildMapContext.BundleInfos)
  27. {
  28. // 注意:原生文件资源包只能包含一个原生文件
  29. bool isRawFile = bundleInfo.IsRawFile;
  30. if (isRawFile)
  31. {
  32. if (bundleInfo.BuildinAssets.Count != 1)
  33. throw new Exception($"The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
  34. continue;
  35. }
  36. // 注意:原生文件不能被其它资源文件依赖
  37. foreach (var assetInfo in bundleInfo.BuildinAssets)
  38. {
  39. if (assetInfo.AllDependAssetInfos != null)
  40. {
  41. foreach (var dependAssetInfo in assetInfo.AllDependAssetInfos)
  42. {
  43. if (dependAssetInfo.IsRawAsset)
  44. throw new Exception($"{assetInfo.AssetPath} can not depend raw asset : {dependAssetInfo.AssetPath}");
  45. }
  46. }
  47. }
  48. }
  49. }
  50. }
  51. }