AssetBundleCollectorSetting.cs 2.8 KB

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