Data调整
This commit is contained in:
@@ -43,7 +43,10 @@ namespace Continentis.MainGame.Card
|
||||
public string functionText;
|
||||
public string cardDescription;
|
||||
|
||||
[Header("Intention")] public float baseWeight = 0f;
|
||||
[Header("Intention")]
|
||||
public List<string> intentionIconKeys;
|
||||
public List<string> intentionValueNames;
|
||||
public float baseWeight = 0f;
|
||||
|
||||
[Header("Attributes")] [Tooltip("可变属性,这个属性会自动设置BaseAttr进入Original,设置Attr,BaseAttrOffset=0,以及DisplayAttr进入Current")]
|
||||
public SerializableDictionary<string, float> variableAttributes = new SerializableDictionary<string, float>();
|
||||
|
||||
@@ -27,8 +27,11 @@ namespace Continentis.MainGame.Card
|
||||
private SerializedProperty functionTextProp;
|
||||
private SerializedProperty cardDescriptionProp;
|
||||
|
||||
private SerializedProperty intentionIconKeysProp;
|
||||
private SerializedProperty intentionValueNamesProp;
|
||||
private SerializedProperty baseWeightProp;
|
||||
|
||||
|
||||
private SerializedProperty variableAttributesProp;
|
||||
private SerializedProperty originalAttributesProp;
|
||||
private SerializedProperty runtimeCurrentAttributesProp;
|
||||
@@ -42,9 +45,6 @@ namespace Continentis.MainGame.Card
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
LoadAllKeywordsFromEditRefs();
|
||||
|
||||
// 在启用时,根据我们修改后的字段名找到对应的SerializedProperty
|
||||
modNameProp = serializedObject.FindProperty("modName");
|
||||
classNameProp = serializedObject.FindProperty("className");
|
||||
@@ -57,7 +57,11 @@ namespace Continentis.MainGame.Card
|
||||
cardLayoutTagsProp = serializedObject.FindProperty("cardLayoutTags");
|
||||
functionTextProp = serializedObject.FindProperty("functionText");
|
||||
cardDescriptionProp = serializedObject.FindProperty("cardDescription");
|
||||
|
||||
intentionIconKeysProp = serializedObject.FindProperty("intentionIconKeys");
|
||||
intentionValueNamesProp = serializedObject.FindProperty("intentionValueNames");
|
||||
baseWeightProp = serializedObject.FindProperty("baseWeight");
|
||||
|
||||
variableAttributesProp = serializedObject.FindProperty("variableAttributes");
|
||||
originalAttributesProp = serializedObject.FindProperty("originalAttributes");
|
||||
runtimeCurrentAttributesProp = serializedObject.FindProperty("runtimeCurrentAttributes");
|
||||
@@ -116,11 +120,7 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
EditorGUILayout.PropertyField(cardRarityProp);
|
||||
EditorGUILayout.PropertyField(cardTypeProp);
|
||||
EditorGUILayout.PropertyField(keywordsProp, true);
|
||||
if (keywordsProp.isExpanded)
|
||||
{
|
||||
DrawKeywordSelector();
|
||||
}
|
||||
DrawListWithEditRefSelector(keywordsProp, "CardKeywords");
|
||||
|
||||
EditorGUILayout.PropertyField(cardSpriteProp);
|
||||
EditorGUILayout.PropertyField(cardLayoutTagsProp, true);
|
||||
@@ -129,6 +129,8 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Attributes", EditorStyles.boldLabel);
|
||||
DrawListWithEditRefSelector(intentionIconKeysProp, "IntentionIconKeys");
|
||||
DrawListWithLocalSelector(intentionValueNamesProp, "variableAttributes");
|
||||
EditorGUILayout.PropertyField(baseWeightProp);
|
||||
EditorGUILayout.PropertyField(variableAttributesProp, true);
|
||||
EditorGUILayout.PropertyField(originalAttributesProp, true);
|
||||
@@ -150,106 +152,5 @@ namespace Continentis.MainGame.Card
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CardDataEditor
|
||||
{
|
||||
private List<string> allAvailableKeywords;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 AssetDatabase 查找项目中的所有 KeywordDatabase 并合并它们的列表
|
||||
/// </summary>
|
||||
private void LoadAllKeywordsFromEditRefs()
|
||||
{
|
||||
// 使用 HashSet 来自动处理重复的关键词
|
||||
HashSet<string> allKeywordsSet = new HashSet<string>();
|
||||
|
||||
// 1. 查找项目中所有类型为 "KeywordDatabase" 的
|
||||
// "t:KeywordDatabase" 是一个搜索过滤器,t: 表示按类型搜索
|
||||
string[] guids = AssetDatabase.FindAssets("t:ModEditReference");
|
||||
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
// 2. 将 GUID 转换为资产路径
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
|
||||
// 3. 加载该路径下的 ScriptableObject
|
||||
ModEditReference editRef = AssetDatabase.LoadAssetAtPath<ModEditReference>(assetPath);
|
||||
EditKeywordsReference cardKeywordsRef = editRef.cardKeywordsReference;
|
||||
|
||||
if (cardKeywordsRef != null && cardKeywordsRef.keywordRefs != null)
|
||||
{
|
||||
// 4. 将词库中的所有词添加到 Set 中
|
||||
foreach (string keyword in cardKeywordsRef.keywordRefs.Keys)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keyword))
|
||||
{
|
||||
allKeywordsSet.Add(keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 将 Set 转换为 List 并排序,以便在菜单中清晰显示
|
||||
allAvailableKeywords = allKeywordsSet.ToList();
|
||||
allAvailableKeywords.Sort();
|
||||
}
|
||||
|
||||
private void DrawKeywordSelector()
|
||||
{
|
||||
// 1. 检查是否找到了任何关键词
|
||||
if (allAvailableKeywords == null || allAvailableKeywords.Count == 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("在项目中没有找到任何 KeywordDatabase,或者词库为空。", MessageType.Warning);
|
||||
// 显示一个刷新按钮,以防用户刚刚创建了词库
|
||||
if (GUILayout.Button("Refresh Keyword Edit References"))
|
||||
{
|
||||
LoadAllKeywordsFromEditRefs();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> currentKeywords = (target as CardData)!.keywords;
|
||||
|
||||
// 2. 找出尚未添加的关键词
|
||||
List<string> keywordsToAdd = allAvailableKeywords.Except(currentKeywords).ToList();
|
||||
|
||||
// 3. 如果所有关键词都添加了,显示提示
|
||||
if (keywordsToAdd.Count == 0)
|
||||
{
|
||||
EditorGUILayout.HelpBox("所有可用的关键词都已添加。", MessageType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 4. 绘制 "Add Keyword" 按钮
|
||||
if (GUILayout.Button("Add Keyword from Edit Refs..."))
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
foreach (string keyword in keywordsToAdd)
|
||||
{
|
||||
menu.AddItem(new GUIContent(keyword), false, () => {
|
||||
AddKeywordToList(keyword);
|
||||
});
|
||||
}
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
}
|
||||
|
||||
// 5. (可选) 添加一个手动刷新按钮
|
||||
// 因为 AssetDatabase.FindAssets() 速度很快,所以我们也可以在每次GUI绘制时都调用
|
||||
// 但如果词库很多,使用按钮刷新更好。
|
||||
/*if (GUILayout.Button("Refresh Keyword Databases"))
|
||||
{
|
||||
LoadAllKeywordsFromEditRefs();
|
||||
}*/
|
||||
}
|
||||
|
||||
private void AddKeywordToList(string keyword)
|
||||
{
|
||||
keywordsProp.InsertArrayElementAtIndex(keywordsProp.arraySize);
|
||||
SerializedProperty newElement = keywordsProp.GetArrayElementAtIndex(keywordsProp.arraySize - 1);
|
||||
newElement.stringValue = keyword;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user