private static void ShowElements(SerializedProperty list, EditorListOption options, ElementCondition condition) { bool showElementLabels = (options & EditorListOption.ElementLabels) != 0, showButtons = (options & EditorListOption.Buttons) != 0, showAdd = (options & EditorListOption.AddButton) != 0; for (int i = 0; i < list.arraySize; i++) { if (condition != null && !condition(list.GetArrayElementAtIndex(i))) { ConditionFullfiled = false; InvalidElements.Add(i); } EditorGUILayout.BeginVertical(); if (showButtons) { GUILayout.BeginHorizontal(); } if (showElementLabels) { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), GUILayout.ExpandWidth(true)); } else { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), GUIContent.none, GUILayout.ExpandWidth(true)); } if (showButtons) { ShowButtons(list, i); GUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } if (((showButtons && list.arraySize == 0) || showAdd) && GUILayout.Button(addButtonContent, EditorStyles.miniButton)) { list.arraySize++; } }
public static void Show(SerializedProperty list, EditorListOption options = EditorListOption.Default, ElementCondition condition = null) { ConditionFullfiled = true; InvalidElements.Clear(); if (!list.isArray) { EditorGUILayout.HelpBox(list.name + " is neither an array nor a list!", MessageType.Error); return; } bool showListLabel = (options & EditorListOption.ListLabel) != 0, showListSize = (options & EditorListOption.ListSize) != 0; if (showListLabel) { EditorGUILayout.PropertyField(list); EditorGUI.indentLevel += 1; } if (!showListLabel || list.isExpanded) { //if (showListSize) // EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size")); //ShowElements(list, options); SerializedProperty size = list.FindPropertyRelative("Array.size"); if (showListSize) { EditorGUILayout.PropertyField(size); } if (size.hasMultipleDifferentValues) { EditorGUILayout.HelpBox("Not showing lists with different sizes.", MessageType.Info); } else { ShowElements(list, options, condition); } } if (!ConditionFullfiled) { string number = ""; foreach (int i in InvalidElements) { number += i + ", "; } EditorGUILayout.HelpBox("Elements: " + number + "are not fulfiling given conditions!", MessageType.Error); } if (showListLabel) { EditorGUI.indentLevel -= 1; } }