Hi everyone, I’m working on a PropertyDrawer to allow a NativeList to be displayed in the Inspector. Here is what I have right now:
/// <summary>
/// PropertyDrawer for a NativeList
/// </summary>
[CustomPropertyDrawer(typeof(NativeList<TestNodeData>))]
public sealed class NativeListPropertyDrawer : PropertyDrawer
{
#region Public methods
/// <summary>
/// Called when the UI is drawn
/// </summary>
/// <param name="position">The position of the field</param>
/// <param name="property">The property to serialize</param>
/// <param name="label">The text</param>
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginChangeCheck();
bool fold = true;
this.DrawPropertyArray(property, ref fold);
if (EditorGUI.EndChangeCheck())
{
//property.boxedValue = new FixedString4096Bytes(fixedStringValue);
}
}
/// <summary>
/// Ensures the field will stay at the proper position
/// </summary>
/// <param name="property">The property</param>
/// <param name="label">The text</param>
/// <returns>The proper height of the field</returns>
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
#endregion
#region Private methods
private void DrawPropertyArray(SerializedProperty property, ref bool fold)
{
fold = EditorGUILayout.Foldout(fold, property.displayName, true);
if (fold)
{
SerializedProperty arraySizeProp = property.FindPropertyRelative("TestNodeDatas.Length");
EditorGUILayout.PropertyField(arraySizeProp);
EditorGUI.indentLevel++;
for (int i = 0; i < arraySizeProp.intValue; ++i)
{
EditorGUILayout.PropertyField(property.GetArrayElementAtIndex(i));
}
EditorGUI.indentLevel--;
}
}
#endregion
}
However, OnGUI() is not even called. It seems the PropertyDrawer doesn’t recognizes the type passed in parameter to the CustomPropertyDrawer attribute. Using the official documentation for Serialization, I tried implementing a binary adapter for a NativeList, hoping this would be the cause of my issue, but nothing changed.
If anyone’s been working on a similar project, please let me know how you managed to serialize and display a nativeCollection in the Inspector.