Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change ReorderableList's element height in Inspector view

Tags:

c#

unity3d

I created custom inspector for my Journal class to display List<T> as ReorderableList<T>. To display class structure I wrote following code:

private ReorderableList list;

private void OnEnable()
{
            list.drawElementCallback =
            (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect = new Rect(rect.x, rect.y, rect.width, rect.height * 2);
                var element = list.serializedProperty.GetArrayElementAtIndex(index);
                rect.y += 2;
                EditorGUI.PropertyField(
                    new Rect(rect.x, rect.y, 100, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("Name"), GUIContent.none);
                EditorGUI.PropertyField(
                    new Rect(rect.x + 100, rect.y, rect.width - 100, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("Image"), GUIContent.none);
                EditorGUI.PropertyField(
                    new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight + 2f, rect.width, EditorGUIUtility.singleLineHeight),
                    element.FindPropertyRelative("Description"), GUIContent.none);
            };

I expected it to be displayed like this:

[1: Name] [1: Picture]
[1: Description]
[2: Name] [2: Picture]
[2: Description]

But in result, "Description" of the first element overlapping with "Name" and "Picture" of the second element and so on.

enter image description here

And I can't find any way to increase ReorderableList's element height. Setting rect.min doesn't help

like image 897
Utamaru Avatar asked Sep 27 '22 09:09

Utamaru


1 Answers

list.elementHeight = EditorGUIUtility.singleLineHeight * 2f;
like image 131
Utamaru Avatar answered Oct 16 '22 11:10

Utamaru