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

116 lines
5.9 KiB
C#
Raw Normal View History

2025-10-23 00:49:44 -04:00
#if UNITY_EDITOR
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 _classFullNameProp;
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");
_classFullNameProp = serializedObject.FindProperty("classFullName");
_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)
DrawTypeSelectorGUI(_classFullNameProp, "Equipment Class", typeof(EquipmentBase), "Continentis.Mods", ".Equipments");
}
else
{
// 如果不勾选,则显示手动输入字段
EditorGUILayout.PropertyField(_modNameProp);
EditorGUILayout.PropertyField(_classNameProp);
EditorGUILayout.PropertyField(_displayNameProp);
}
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