AssetBundleCollectorGroup.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 AssetBundleCollectorGroup
  11. {
  12. /// <summary>
  13. /// 分组名称
  14. /// </summary>
  15. public string GroupName = string.Empty;
  16. /// <summary>
  17. /// 分组描述
  18. /// </summary>
  19. public string GroupDesc = string.Empty;
  20. /// <summary>
  21. /// 资源分类标签
  22. /// </summary>
  23. public string AssetTags = string.Empty;
  24. /// <summary>
  25. /// 分组激活规则
  26. /// </summary>
  27. public string ActiveRuleName = nameof(EnableGroup);
  28. /// <summary>
  29. /// 分组的收集器列表
  30. /// </summary>
  31. public List<AssetBundleCollector> Collectors = new List<AssetBundleCollector>();
  32. /// <summary>
  33. /// 检测配置错误
  34. /// </summary>
  35. public void CheckConfigError()
  36. {
  37. if (AssetBundleCollectorSettingData.HasActiveRuleName(ActiveRuleName) == false)
  38. throw new Exception($"Invalid {nameof(IActiveRule)} class type : {ActiveRuleName} in group : {GroupName}");
  39. foreach (var collector in Collectors)
  40. {
  41. collector.CheckConfigError();
  42. }
  43. }
  44. /// <summary>
  45. /// 获取打包收集的资源文件
  46. /// </summary>
  47. public List<CollectAssetInfo> GetAllCollectAssets(EBuildMode buildMode)
  48. {
  49. Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(10000);
  50. // 检测分组是否激活
  51. IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
  52. if (activeRule.IsActiveGroup() == false)
  53. {
  54. return new List<CollectAssetInfo>();
  55. }
  56. // 收集打包资源
  57. foreach (var collector in Collectors)
  58. {
  59. var temper = collector.GetAllCollectAssets(buildMode, this);
  60. foreach (var assetInfo in temper)
  61. {
  62. if (result.ContainsKey(assetInfo.AssetPath) == false)
  63. result.Add(assetInfo.AssetPath, assetInfo);
  64. else
  65. throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath} in group : {GroupName}");
  66. }
  67. }
  68. // 检测可寻址地址是否重复
  69. if (AssetBundleCollectorSettingData.Setting.EnableAddressable)
  70. {
  71. HashSet<string> adressTemper = new HashSet<string>();
  72. foreach (var collectInfoPair in result)
  73. {
  74. if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector)
  75. {
  76. string address = collectInfoPair.Value.Address;
  77. if (adressTemper.Contains(address) == false)
  78. adressTemper.Add(address);
  79. else
  80. throw new Exception($"The address is existed : {address} in group : {GroupName}");
  81. }
  82. }
  83. }
  84. // 返回列表
  85. return result.Values.ToList();
  86. }
  87. }
  88. }