My data class
[Serializable]
public class Data<T>
{
private T _value;
public T Value
{
get => _value;
set
{
_value = value;
}
}
public EventVar(T value)
{
Value = value;
}
}
How to show Value in the inspector using PropertyDrawer
[CustomPropertyDrawer(typeof(Data<>))]
public class DataUI: PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
// Draw label
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
// Don't make child fields be indented
int indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
// Calculate rects
Rect valueRect = new(position.x, position.y, position.width, position.height);
// Draw fields - pass GUIContent.none to each so they are drawn without labels
//EditorGUI.PropertyField(valueRect, property.FindPropertyRelative("Value"), GUIContent.none);
Debug.Log(property.FindPropertyRelative("Value")); // This log null
// Set indent back to what it was
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}