Why doesn’t the following piece of code work?
using System.Collections.Generic;
using UnityEditor;
using UnityEngine.UIElements;
[CustomEditor(typeof(CardSet), editorForChildClasses: true)]
public class CardSetEditor : Editor
{
private List<string> cards = new List<string>() { "A", "B", "C" };
public override VisualElement CreateInspectorGUI()
{
var list = new ListView(cards, 30, MakeItem, BindItem);
list.style.flexGrow = 1f;
return list;
}
private void BindItem(VisualElement label, int index)
{
((Label)label).text = cards[index];
}
private VisualElement MakeItem()
{
return new Label();
}
}
Following the documentation, I would expect the ListView to fill the entire space of the custom editor in the inspector window, but for some reason, the parent VisualElements (which I do not have control over), all have zero height, so nothing is visible. Do I have to set a fixed size for my inspector? But if so, why can’t I let Unity calculate the height as it did with IMGUI previously?