using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace YooAsset.Editor { public class AssetBundleCollectorSetting : ScriptableObject { /// /// 是否启用可寻址资源定位 /// public bool EnableAddressable = false; /// /// 分组列表 /// public List Groups = new List(); /// /// 检测配置错误 /// public void CheckConfigError() { foreach (var group in Groups) { group.CheckConfigError(); } } /// /// 修复配置错误 /// public bool FixConfigError() { bool result = false; foreach (var group in Groups) { foreach (var collector in group.Collectors) { bool isFixed = collector.FixConfigError(); if (isFixed) { result = true; } } } return result; } /// /// 获取所有的资源标签 /// public List GetAllTags() { HashSet result = new HashSet(); foreach (var group in Groups) { List groupTags = StringUtility.StringToStringList(group.AssetTags, ';'); foreach (var tag in groupTags) { if (result.Contains(tag) == false) result.Add(tag); } foreach (var collector in group.Collectors) { List collectorTags = StringUtility.StringToStringList(collector.AssetTags, ';'); foreach (var tag in collectorTags) { if (result.Contains(tag) == false) result.Add(tag); } } } return result.ToList(); } /// /// 获取打包收集的资源文件 /// public List GetAllCollectAssets(EBuildMode buildMode) { Dictionary result = new Dictionary(10000); // 收集打包资源 foreach (var group in Groups) { var temper = group.GetAllCollectAssets(buildMode); foreach (var assetInfo in temper) { if (result.ContainsKey(assetInfo.AssetPath) == false) result.Add(assetInfo.AssetPath, assetInfo); else throw new Exception($"The collecting asset file is existed : {assetInfo.AssetPath}"); } } // 检测可寻址地址是否重复 if (EnableAddressable) { HashSet adressTemper = new HashSet(); foreach (var collectInfoPair in result) { if (collectInfoPair.Value.CollectorType == ECollectorType.MainAssetCollector) { string address = collectInfoPair.Value.Address; if (adressTemper.Contains(address) == false) adressTemper.Add(address); else throw new Exception($"The address is existed : {address}"); } } } // 返回列表 return result.Values.ToList(); } } }