Files
Continentis/docs/References/EditorBaseCollection.cs
SoulliesOfficial d09b58fd80 架构大更
2026-03-20 11:56:50 -04:00

56 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using System.Linq;
using Cielonos.Core;
using Sirenix.OdinInspector;
using SLSUtilities.General;
using UnityEngine;
#if UNITY_EDITOR
using Sirenix.OdinInspector.Editor;
#endif
namespace Cielonos.MainGame
{
[CreateAssetMenu(fileName = "EditorBaseCollection", menuName = "Cielonos/BaseCollections/EditorBaseCollection")]
public partial class EditorBaseCollection : BaseCollection<EditorBaseCollection>
{
[Tooltip("Key 为词条 IDValue 为词条描述(将显示在 Tooltip 中)")]
[SerializedDictionarySettings("Key", "Description")]
[ToolbarButton("OpenAttributeGenerator", SdfIconType.FileCode, "打开词条生成器窗口")]
public SerializedDictionary<string, string> characterAttributes = new SerializedDictionary<string, string>();
#if UNITY_EDITOR
public static IEnumerable<ValueDropdownItem<string>> GetCharacterAttributesDropdown(InspectorProperty property)
{
IEnumerable<ValueDropdownItem<string>> allItems = Instance.characterAttributes
.Select(kvp => new ValueDropdownItem<string>
{
Text = $"{kvp.Key} ({kvp.Value})",
Value = kvp.Key
});
object dict = SerializedDictionaryHelper.GetDictionaryFromKey(property);
if (dict is IEnumerable<KeyValuePair<string, float>> 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<string, string> dict)
{
// 打开我们刚才写的窗口,并传入当前的字典数据
DictionaryCodeGeneratorWindow.Open(dict, "CharacterAttribute", "Cielonos.MainGame");
}
#endif
}
public partial class EditorBaseCollection
{
}
}