Files
aibis-dream/Assets/Scripts/SubWay/ConditionalFieldDrawer.cs
T
2024-11-28 19:50:29 +08:00

32 lines
1.1 KiB
C#

using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(ConditionalFieldAttribute))]
public class ConditionalFieldDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
ConditionalFieldAttribute conditional = (ConditionalFieldAttribute)attribute;
SerializedProperty conditionProperty = property.serializedObject.FindProperty(conditional.conditionField);
if (conditionProperty != null && conditionProperty.boolValue)
{
EditorGUI.PropertyField(position, property, label, true);
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
ConditionalFieldAttribute conditional = (ConditionalFieldAttribute)attribute;
SerializedProperty conditionProperty = property.serializedObject.FindProperty(conditional.conditionField);
if (conditionProperty != null && conditionProperty.boolValue)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
return 0f; // 隐藏字段时的高度
}
}