public static bool DrawCompactArray(SerializedProperty property, string propertyName, GUIContent label, int maxLineItems = 3, bool includeChildren = true, params GUILayoutOption[] options) { if (property != null) { if (property.isArray) { if (maxLineItems <= 0) { maxLineItems = 3; } // Foldout + Size or Label if array length <= 0 EditorGUILayout.BeginHorizontal(); property.isExpanded = EditorGUILayout.Foldout(property.isExpanded, label, true, property.arraySize > 0 ? EditorStyles.foldout : Styles.FoldoutNoArrow); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Size"), EditorStyles.label, CalcMinMaxWidth(new GUIContent("Size"), EditorStyles.label)); property.arraySize = Mathf.Abs(EditorGUILayout.IntField(new GUIContent(string.Empty), property.arraySize, GUILayout.MaxWidth(48.0f))); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); // Draw array items if foldout is expanded and array length > 0 if (property.isExpanded && property.arraySize > 0) { int i = 0; SerializedProperty emptyProperty = property.GetArrayElementAtIndex(0).Copy(); emptyProperty.ClearValues(); float minLineLabelWidth, maxLineLabelWidth; Styles.IndentedRightAlignedMiniLabel.CalcMinMaxWidth(new GUIContent((property.arraySize - 1).ToString()), out minLineLabelWidth, out maxLineLabelWidth); EditorGUILayout.BeginVertical(); while (i < property.arraySize) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent(i.ToString()), Styles.IndentedRightAlignedMiniLabel, GUILayout.MinWidth(minLineLabelWidth), GUILayout.MaxWidth(maxLineLabelWidth)); for (int lineIndex = 0; lineIndex < maxLineItems; ++lineIndex, ++i) { if (i < property.arraySize) { EditorGUILayout.PropertyField(property.GetArrayElementAtIndex(i), new GUIContent(string.Empty), true); } else { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.PropertyField(emptyProperty, new GUIContent(string.Empty), false); EditorGUI.EndDisabledGroup(); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } } else { EditorGUILayout.PropertyField(property, label, includeChildren, options); } return(true); } return(DrawErrorLabel(propertyName, $"{label.text}\n{label.tooltip}")); }