40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using Lemon.GenericLib.Generics;
|
|
|
|
namespace Lemon.GenericLib.Editor {
|
|
[CustomPropertyDrawer(typeof(Optional<>))]
|
|
public class OptionalPropertyDrawer : PropertyDrawer
|
|
{
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
{
|
|
var valueProperty = property.FindPropertyRelative("value");
|
|
return EditorGUI.GetPropertyHeight(valueProperty);
|
|
}
|
|
|
|
public override void OnGUI(
|
|
Rect position,
|
|
SerializedProperty property,
|
|
GUIContent label
|
|
)
|
|
{
|
|
var valueProperty = property.FindPropertyRelative("value");
|
|
var enabledProperty = property.FindPropertyRelative("enabled");
|
|
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
position.width -= 24;
|
|
EditorGUI.BeginDisabledGroup(!enabledProperty.boolValue);
|
|
EditorGUI.PropertyField(position, valueProperty, label, true);
|
|
EditorGUI.EndDisabledGroup();
|
|
|
|
position.x += position.width + 24;
|
|
position.width = position.height = EditorGUI.GetPropertyHeight(enabledProperty);
|
|
position.x -= position.width;
|
|
EditorGUI.PropertyField(position, enabledProperty, GUIContent.none);
|
|
EditorGUI.EndProperty();
|
|
}
|
|
}
|
|
}
|
|
|
|
|