#if UNITY_EDITOR using System.Linq; using UnityEditor; using UnityEngine; using YooAsset.Editor; namespace AIGame.EditorTools { /// UI Prefab 与自动图集收进 Art;每个图集与原图绑定为同一资源包。 public static class SetupUiBundleCollector { [MenuItem("Tools/UI/Setup UI Bundle Collector")] public static string Setup() { UiSpriteAtlasGenerator.GenerateAll(); var package = BundleCollectorSettingData.Setting.Packages.FirstOrDefault(p => p.PackageName == "Art"); if (package == null) throw new System.InvalidOperationException("Set up the Art package before UI collection."); var group = package.Groups.FirstOrDefault(g => g.GroupName == "UI"); if (group == null) group = BundleCollectorSettingData.CreateGroup(package, "UI"); group.GroupDesc = "Candy UI"; group.AssetTags = "ui"; group.ActiveRuleName = nameof(EnableGroup); BundleCollectorSettingData.ModifyGroup(package, group); const string path = "Assets/Bundles/UI/Prefab"; var collector = group.Collectors.FirstOrDefault(c => c.CollectPath == path); if (collector == null) { collector = new BundleCollector { CollectPath = path, CollectorGUID = AssetDatabase.AssetPathToGUID(path), CollectorType = ECollectorType.MainAssetCollector, AddressRuleName = nameof(AddressByFileName), PackRuleName = nameof(PackSeparately), FilterRuleName = nameof(CollectPrefab), AssetTags = "ui" }; BundleCollectorSettingData.CreateCollector(group, collector); } ConfigureAtlasCollector(group, HotUpdate.UI.UiAtlasPaths.AtlasRoot, ECollectorType.MainAssetCollector, nameof(CollectUiAtlas), "ui"); ConfigureAtlasCollector(group, HotUpdate.UI.UiAtlasPaths.TextureRoot, ECollectorType.DependAssetCollector, nameof(CollectUiAtlasTexture), ""); package.CheckConfigError(); BundleCollectorSettingData.SaveFile(); return "Art/UI: UI prefabs by name; generated atlases by name; source sprites in the same bundle as their atlas."; } private static void ConfigureAtlasCollector(BundleCollectorGroup group, string path, ECollectorType type, string filter, string tags) { var collector = group.Collectors.FirstOrDefault(c => c.CollectPath == path); bool created = collector == null; if (created) collector = new BundleCollector { CollectPath = path }; collector.CollectorGUID = AssetDatabase.AssetPathToGUID(path); collector.CollectorType = type; collector.AddressRuleName = nameof(AddressByFileName); collector.PackRuleName = nameof(PackUiAtlas); collector.FilterRuleName = filter; collector.AssetTags = tags; if (created) BundleCollectorSettingData.CreateCollector(group, collector); else BundleCollectorSettingData.ModifyCollector(group, collector); } } } #endif