1

我正在尝试创建一个可重新排序的列表,但我在使用 EditorGUILayout 时遇到了问题。如果我使用 EditorGUI 它可以正常工作,但是这些字段的大小是静态的(除非我每次都手动计算大小)。

这是我正在做的事情:

    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();
    };

当我使用 EditorGUILayout 时,控件显示在 Reorderable 列表下方。我仍然可以交换命令,但内容总是显示在列表下方。

替代文字

4

1 回答 1

2

正如您在回调参数中看到的那样。有一个 Rect 参数,它是显示 GUI 元素的区域。您不能使用 GUILayout 或 EditorGUILayout。你应该自己计算位置。

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"));
};
于 2015-05-15T09:09:13.387 回答