AssetBundleCollectorPackage.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEditor;
  7. namespace YooAsset.Editor
  8. {
  9. [Serializable]
  10. public class AssetBundleCollectorPackage
  11. {
  12. /// <summary>
  13. /// 包裹名称
  14. /// </summary>
  15. public string PackageName = string.Empty;
  16. /// <summary>
  17. /// 包裹描述
  18. /// </summary>
  19. public string PackageDesc = string.Empty;
  20. /// <summary>
  21. /// 分组列表
  22. /// </summary>
  23. public List<AssetBundleCollectorGroup> Groups = new List<AssetBundleCollectorGroup>();
  24. /// <summary>
  25. /// 检测配置错误
  26. /// </summary>
  27. public void CheckConfigError()
  28. {
  29. foreach (var group in Groups)
  30. {
  31. group.CheckConfigError();
  32. }
  33. }
  34. /// <summary>
  35. /// 修复配置错误
  36. /// </summary>
  37. public bool FixConfigError()
  38. {
  39. bool isFixed = false;
  40. foreach (var group in Groups)
  41. {
  42. if (group.FixConfigError())
  43. {
  44. isFixed = true;
  45. }
  46. }
  47. return isFixed;
  48. }
  49. /// <summary>
  50. /// 获取打包收集的资源文件
  51. /// </summary>
  52. public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command)
  53. {
  54. Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
  55. // 收集打包资源
  56. foreach (var group in Groups)
  57. {
  58. var temper = group.GetAllCollectAssets(command);
  59. foreach (var assetInfo in temper)
  60. {
  61. if (result.ContainsKey(assetInfo.AssetPath) == false)
  62. result.Add(assetInfo.AssetPath, assetInfo);
  63. else
  64. throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}");
  65. }
  66. }
  67. // 检测可寻址地址是否重复
  68. if (command.EnableAddressable)
  69. {
  70. var addressTemper = new Dictionary<string, string>();
  71. foreach (var collectInfoPair in result)
  72. {
  73. if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
  74. {
  75. string address = collectInfoPair.Value.Address;
  76. string assetPath = collectInfoPair.Value.AssetPath;
  77. if (addressTemper.TryGetValue(address, out var existed) == false)
  78. addressTemper.Add(address, assetPath);
  79. else
  80. throw new Exception($"The address is existed : {address} \nAssetPath:\n {existed}\n {assetPath}");
  81. }
  82. }
  83. }
  84. // 返回列表
  85. return result.Values.ToList();
  86. }
  87. /// <summary>
  88. /// 获取所有的资源标签
  89. /// </summary>
  90. public List<string> GetAllTags()
  91. {
  92. HashSet<string> result = new HashSet<string>();
  93. foreach (var group in Groups)
  94. {
  95. List<string> groupTags = EditorTools.StringToStringList(group.AssetTags, ';');
  96. foreach (var tag in groupTags)
  97. {
  98. if (result.Contains(tag) == false)
  99. result.Add(tag);
  100. }
  101. foreach (var collector in group.Collectors)
  102. {
  103. List<string> collectorTags = EditorTools.StringToStringList(collector.AssetTags, ';');
  104. foreach (var tag in collectorTags)
  105. {
  106. if (result.Contains(tag) == false)
  107. result.Add(tag);
  108. }
  109. }
  110. }
  111. return result.ToList();
  112. }
  113. }
  114. }