Files
Continentis/Assets/Scripts/MainGame/Equipment/Editor/EquipmentDataEditor.cs

134 lines
6.6 KiB
C#
Raw Normal View History

2025-10-23 00:49:44 -04:00
#if UNITY_EDITOR
2025-10-24 09:11:22 -04:00
using System;
2025-10-23 00:49:44 -04:00
using UnityEditor;
using UnityEngine;
using Continentis.MainGame.Card;
using Continentis.MainGame.Character;
using SLSFramework.UModAssistance;
namespace Continentis.MainGame.Equipment
{
[CustomEditor(typeof(EquipmentData))]
public class EquipmentDataEditor : DataEditor
{
// Fundamental
private SerializedProperty _haveCustomClassProp;
private SerializedProperty _modNameProp;
private SerializedProperty _classNameProp;
private SerializedProperty _displayNameProp;
private SerializedProperty _tagsProp;
private SerializedProperty _equipmentRarityProp;
private SerializedProperty _equipmentIconProp;
private SerializedProperty _equipmentDescriptionProp;
// Attributes
private SerializedProperty _coreNumericChangeProp;
private SerializedProperty _corePercentageChangeOfAccumulationProp;
private SerializedProperty _corePercentageChangeOfMultiplicationProp;
private SerializedProperty _generalNumericChangeProp;
private SerializedProperty _generalPercentageChangeOfAccumulationProp;
private SerializedProperty _generalPercentageChangeOfMultiplicationProp;
// References
private SerializedProperty _prefabRefsProp;
private SerializedProperty _derivativeCardDataRefsProp;
private SerializedProperty _derivativeCharacterDataRefsProp;
private SerializedProperty _belongingCardDataRefsProp;
protected override void OnEnable()
{
base.OnEnable();
// --- 在OnEnable中找到所有属性 ---
_haveCustomClassProp = serializedObject.FindProperty("haveCustomClass");
_modNameProp = serializedObject.FindProperty("modName");
_classNameProp = serializedObject.FindProperty("className");
_displayNameProp = serializedObject.FindProperty("displayName");
_tagsProp = serializedObject.FindProperty("tags");
_equipmentRarityProp = serializedObject.FindProperty("equipmentRarity");
_equipmentIconProp = serializedObject.FindProperty("equipmentIcon");
_equipmentDescriptionProp = serializedObject.FindProperty("equipmentDescription");
_coreNumericChangeProp = serializedObject.FindProperty("coreNumericChange");
_corePercentageChangeOfAccumulationProp = serializedObject.FindProperty("corePercentageChangeOfAccumulation");
_corePercentageChangeOfMultiplicationProp = serializedObject.FindProperty("corePercentageChangeOfMultiplication");
_generalNumericChangeProp = serializedObject.FindProperty("generalNumericChange");
_generalPercentageChangeOfAccumulationProp = serializedObject.FindProperty("generalPercentageChangeOfAccumulation");
_generalPercentageChangeOfMultiplicationProp = serializedObject.FindProperty("generalPercentageChangeOfMultiplication");
_prefabRefsProp = serializedObject.FindProperty("prefabRefs");
_derivativeCardDataRefsProp = serializedObject.FindProperty("derivativeCardDataRefs");
_derivativeCharacterDataRefsProp = serializedObject.FindProperty("derivativeCharacterDataRefs");
_belongingCardDataRefsProp = serializedObject.FindProperty("belongingCardDataRefs");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
// --- 按照你在EquipmentData.cs中声明的顺序手动绘制所有字段 ---
EditorGUILayout.LabelField("Fundamental", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_haveCustomClassProp);
// --- 核心逻辑:根据 haveCustomClass 的值来决定显示/隐藏 ---
if (_haveCustomClassProp.boolValue)
{
// 如果勾选则显示class选择器 (假设基类为EquipmentBase, 命名空间为.Equipments)
2025-11-10 11:18:19 -05:00
DrawSearchableTypeSelector(
_classNameProp,
"Equipment Class",
typeof(EquipmentBase),
(outType) =>
{
string className = outType.Name;
string modName = outType.Namespace!.Replace("Continentis.Mods.", "").Split('.')[0];
string displayName = "Card_" + modName + "_" + className + "_DisplayName";
_classNameProp.stringValue = className;
_modNameProp.stringValue = modName;
_displayNameProp.stringValue = displayName;
},
"Continentis.Mods",
"Equipments");
2025-10-24 09:11:22 -04:00
EditorGUI.BeginDisabledGroup(true);
2025-10-23 00:49:44 -04:00
}
2025-10-24 09:11:22 -04:00
EditorGUILayout.PropertyField(_modNameProp);
EditorGUILayout.PropertyField(_classNameProp);
EditorGUILayout.PropertyField(_displayNameProp);
if (_haveCustomClassProp.boolValue)
2025-10-23 00:49:44 -04:00
{
2025-10-24 09:11:22 -04:00
EditorGUI.EndDisabledGroup();
2025-10-23 00:49:44 -04:00
}
EditorGUILayout.PropertyField(_tagsProp, true);
EditorGUILayout.PropertyField(_equipmentRarityProp);
EditorGUILayout.PropertyField(_equipmentIconProp);
EditorGUILayout.PropertyField(_equipmentDescriptionProp);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Attributes", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(_coreNumericChangeProp, true);
EditorGUILayout.PropertyField(_corePercentageChangeOfAccumulationProp, true);
EditorGUILayout.PropertyField(_corePercentageChangeOfMultiplicationProp, true);
EditorGUILayout.PropertyField(_generalNumericChangeProp, true);
EditorGUILayout.PropertyField(_generalPercentageChangeOfAccumulationProp, true);
EditorGUILayout.PropertyField(_generalPercentageChangeOfMultiplicationProp, true);
EditorGUILayout.Space();
EditorGUILayout.LabelField("References", EditorStyles.boldLabel);
DrawCharacterListGUI<GameObject>(_prefabRefsProp);
DrawCharacterListGUI<CardData>(_derivativeCardDataRefsProp);
DrawCharacterListGUI<CharacterData>(_derivativeCharacterDataRefsProp);
DrawCharacterListGUI<CardData>(_belongingCardDataRefsProp);
// 处理所有可能发生的ObjectPicker事件
HandleObjectPicker();
serializedObject.ApplyModifiedProperties();
}
}
}
#endif