I’m currently implementing a ListView
that’s bound to a SerializedProperty
array using the following code:
public class CustomPropertyDrawerList : VisualElement
{
private SerializedProperty _arrayProperty;
private ListView _listView;
public CustomPropertyDrawerList(SerializedProperty arrayProperty)
{
this._arrayProperty = arrayProperty.Copy();
_listView = new ListView();
_listView.virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight;
_listView.BindProperty(this._arrayProperty);
Add(_listView);
}
}
Additionally, I have a custom attribute and a corresponding CustomPropertyDrawer
that shows a sprite preview:
[CustomPropertyDrawer(typeof(PreviewAttribute))]
public class PreviewDrawer : CustomPropertyDrawer
{
// Implementation for rendering a sprite preview
}
Everything works as expected for the first one or two elements (e.g., element 0 and 1) in the list. However, subsequent elements often render incorrectly: sometimes the previews show up in the wrong order or don’t display at all.
Has anyone encountered similar issues with CustomPropertyDrawer
s in a bound ListView
? Is there a known limitation or workaround when using custom drawers with a serialized list that’s bound at runtime? Any guidance or best practices would be much appreciated!