I customize a Editor to implement my own CreateInspectorGUI. I add a ListView with each element is a IMGUIContainer. I find if there has any dropdown menu inside the IMGUIContainer, the inspector work incorrectly. If you change the dropdown menu, it seems the internal state is broken.
The code like this:
[CreateAssetMenu(fileName = "ExampleObj", menuName = "Test/ExampleObj")]
public sealed class ExampleObj : ScriptableObject
{
[SerializeField]
private Entry[] entries;
public enum Option
{
A,
B,
C,
}
[Serializable]
public struct Entry
{
public Option option;
public string text;
}
}
[CustomEditor(typeof(ExampleObj))]
public sealed class ExampleObjEditor : Editor
{
public override VisualElement CreateInspectorGUI()
{
var entries = this.serializedObject.FindProperty("entries");
var list = new ListView
{
reorderable = true,
reorderMode = ListViewReorderMode.Animated,
virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight,
showBorder = true,
showBoundCollectionSize = false,
showAddRemoveFooter = true,
bindingPath = "entries",
makeItem = () => new IMGUIContainer(),
bindItem = (ve, index) =>
{
var imgui = ve as IMGUIContainer;
imgui.onGUIHandler = () =>
{
if (index >= entries.arraySize)
{
return;
}
var element = entries.GetArrayElementAtIndex(index);
var option = element.FindPropertyRelative("option");
EditorGUILayout.PropertyField(option);
var text = element.FindPropertyRelative("text");
EditorGUILayout.PropertyField(text);
};
},
unbindItem = (ve, index) =>
{
var imgui = ve as IMGUIContainer;
imgui.onGUIHandler = null;
},
};
return list;
}
}
I attach the BUG Demo project with Unity 2022.1.17f1. Open the project, select “Assets/ExampleObj.asset”. Then try to change some enum dropdown in the inspector.
8457602–1122464–BUG Demo.zip (21.5 KB)