2022-01-07 12:21:36 -05:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TriInspector.Drawers
|
|
|
|
|
{
|
|
|
|
|
public abstract class BuiltinDrawerBase<T> : TriValueDrawer<T>
|
|
|
|
|
{
|
|
|
|
|
public sealed override TriElement CreateElement(TriValue<T> propertyValue, TriElement next)
|
|
|
|
|
{
|
|
|
|
|
if (propertyValue.Property.TryGetSerializedProperty(out _))
|
|
|
|
|
{
|
|
|
|
|
return next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.CreateElement(propertyValue, next);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 10:23:27 -05:00
|
|
|
|
public virtual int CompactModeLines => 1;
|
|
|
|
|
public virtual int WideModeLines => 1;
|
|
|
|
|
|
2022-01-07 12:21:36 -05:00
|
|
|
|
public sealed override float GetHeight(float width, TriValue<T> propertyValue, TriElement next)
|
|
|
|
|
{
|
2022-01-15 10:23:27 -05:00
|
|
|
|
var lineHeight = EditorGUIUtility.singleLineHeight;
|
2022-07-03 02:50:28 -04:00
|
|
|
|
var spacing = EditorGUIUtility.standardVerticalSpacing;
|
2022-01-15 10:23:27 -05:00
|
|
|
|
var lines = EditorGUIUtility.wideMode ? WideModeLines : CompactModeLines;
|
2022-07-03 02:50:28 -04:00
|
|
|
|
return lineHeight * lines + spacing * (lines - 1);
|
2022-01-07 12:21:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed override void OnGUI(Rect position, TriValue<T> propertyValue, TriElement next)
|
|
|
|
|
{
|
2022-05-11 04:23:11 -04:00
|
|
|
|
var value = propertyValue.SmartValue;
|
2022-01-07 12:21:36 -05:00
|
|
|
|
|
|
|
|
|
EditorGUI.BeginChangeCheck();
|
|
|
|
|
|
|
|
|
|
value = OnValueGUI(position, propertyValue.Property.DisplayNameContent, value);
|
|
|
|
|
|
|
|
|
|
if (EditorGUI.EndChangeCheck())
|
|
|
|
|
{
|
2024-01-24 04:58:07 -05:00
|
|
|
|
propertyValue.SetValue(value);
|
2022-01-07 12:21:36 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract T OnValueGUI(Rect position, GUIContent label, T value);
|
|
|
|
|
}
|
|
|
|
|
}
|