neoRiley
neoRiley

Reputation: 475

Unity3D ReorderableList fields display below the box

I am trying to create a Reorderable List, but I am having an Issue using EditorGUILayout with it. If I use EditorGUI It works fine, but then the fields are static in size (unless I manually calculate the size every time).

Here is what I am doing:

    list = new ReorderableList(serializedObject, serializedObject.FindProperty("groupSettings"), true, true, true, true);

    list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
        SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(index);

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.PropertyField(element.FindPropertyRelative("poolGroupName"), GUIContent.none);
            EditorGUILayout.PropertyField(element.FindPropertyRelative("minPoolSize"), GUIContent.none);
            EditorGUILayout.PropertyField(element.FindPropertyRelative("maxPoolSize"), GUIContent.none);
            EditorGUILayout.PropertyField(element.FindPropertyRelative("prewarmCount"), GUIContent.none);
            EditorGUILayout.PropertyField(element.FindPropertyRelative("prewarmObject"), GUIContent.none);
        }
        EditorGUILayout.EndHorizontal();
    };

When I use EditorGUILayout, the controls display below the Reorderable list. I can still swap order, but the contents is always displayed below the list.

alt text

Upvotes: 1

Views: 3139

Answers (1)

Rutz
Rutz

Reputation: 216

As you can see at callback parameter. There is Rect parameter which is area to display GUI elements. You cannot use GUILayout or EditorGUILayout. You should calculate position by yourself.

list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
    SerializedProperty element = list.serializedProperty.GetArrayElementAtIndex(index);

    float gap = 10f;
    float numColumns = 5f;
    float width = (rect.width - (numColumns - 1) * gap) / numColumns;
    rect.height = 16f;
    rect.width = width;

    EditorGUI.PropertyField(rect, property.FindPropertyRelative("poolGroupName"));
    rect.x += rect.width + gap;

    EditorGUI.PropertyField(rect, property.FindPropertyRelative("minPoolSize"));
    rect.x += rect.width + gap;

    EditorGUI.PropertyField(rect, property.FindPropertyRelative("maxPoolSize"));

    rect.x += rect.width + gap;
    EditorGUI.PropertyField(rect, property.FindPropertyRelative("prewarmCount"));

    rect.x += rect.width + gap;
    EditorGUI.PropertyField(rect, property.FindPropertyRelative("prewarmObject"));
};

Upvotes: 2

Related Questions