架构大更
This commit is contained in:
56
docs/References/EditorBaseCollection.cs
Normal file
56
docs/References/EditorBaseCollection.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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 为词条 ID,Value 为词条描述(将显示在 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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user