using System; using System.Collections.Generic; using System.Linq; using Cielonos.Core; using Cielonos.MainGame.Buffs.Character; using Sirenix.OdinInspector; using SLSUtilities.General; using UnityEngine; #if UNITY_EDITOR using System.Reflection; using Sirenix.OdinInspector.Editor; #endif namespace Cielonos.MainGame { [CreateAssetMenu(fileName = "EditorBaseCollection", menuName = "Cielonos/BaseCollections/EditorBaseCollection")] public partial class EditorBaseCollection : BaseCollection { [Tooltip("Key 为词条 ID,Value 为词条描述(将显示在 Tooltip 中)")] [SerializedDictionarySettings("Key", "Description")] [ToolbarButton("OpenAttributeGenerator", SdfIconType.FileCode, "打开词条生成器窗口")] public SerializedDictionary characterAttributes = new SerializedDictionary(); #if UNITY_EDITOR public static IEnumerable> GetCharacterAttributesDropdown(InspectorProperty property) { IEnumerable> allItems = Instance.characterAttributes .Select(kvp => new ValueDropdownItem { Text = $"{kvp.Key} ({kvp.Value})", Value = kvp.Key }); object dict = SerializedDictionaryHelper.GetDictionaryFromKey(property); if (dict is IEnumerable> existingDict) { var usedKeys = existingDict.Select(k => k.Key).ToHashSet(); string currentKey = property.ValueEntry.WeakSmartValue as string; return allItems.Where(x => !usedKeys.Contains(x.Value) || x.Value == currentKey); } return allItems; } /// /// 为 BuffVFXPair 的 Key 提供下拉菜单,枚举项目中所有继承自 CharacterBuffBase 的具体类。 /// public static IEnumerable> GetCharacterBuffDropdown(InspectorProperty property) { IEnumerable> allItems = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(asm => { try { return asm.GetTypes(); } catch (ReflectionTypeLoadException e) { return e.Types.Where(t => t != null); } }) .Where(t => t.IsClass && !t.IsAbstract && typeof(CharacterBuffBase).IsAssignableFrom(t)) .OrderBy(t => t.Name) .Select(t => new ValueDropdownItem { Text = t.Name, Value = t.Name }); object dict = SerializedDictionaryHelper.GetDictionaryFromKey(property); if (dict is IEnumerable> existingDict) { var usedKeys = existingDict.Select(k => k.Key).ToHashSet(); string currentKey = property.ValueEntry.WeakSmartValue as string; return allItems.Where(x => !usedKeys.Contains(x.Value) || x.Value == currentKey); } return allItems; } private void OpenAttributeGenerator(SerializedDictionary dict) { // 打开我们刚才写的窗口,并传入当前的字典数据 DictionaryCodeGeneratorWindow.Open(dict, "CharacterAttribute", "Cielonos.MainGame"); } #endif } public partial class EditorBaseCollection { } }