private void ShowElements(SerializedProperty list, EditorListOptions options) { bool showElementLabels = (options & EditorListOptions.ElementLabels) != 0, showButtons = (options & EditorListOptions.Buttons) != 0; for (int i = 0; i < list.arraySize; i++) { if (showButtons) { EditorGUILayout.BeginHorizontal(); } if (showElementLabels) { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i)); } else { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), GUIContent.none); } if (showButtons) { ShowButtons(list, i); EditorGUILayout.EndHorizontal(); } } }
public static void Show(SerializedProperty list, EditorListOptions options = EditorListOptions.Default) { bool showListLabel = (options & EditorListOptions.ListLabel) != 0, showListSize = (options & EditorListOptions.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); } if (showListLabel) { EditorGUI.indentLevel -= 1; } }
private static void ShowElements(SerializedProperty list, EditorListOptions options) { bool showElementLabels = (options & EditorListOptions.ElementLabels) != 0; for (int i = 0; i < list.arraySize; i++) { if (showElementLabels) { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i)); } else { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), GUIContent.none); } } }
// Extracts the option to hide the labels of the elements if necessary private static void ShowElements(SerializedProperty list, EditorListOptions options) { if (!list.isArray) { EditorGUILayout.HelpBox(list.name + " is neither an array nor a list!", MessageType.Error); return; } bool showElementLabels = (options & EditorListOptions.ElementLabels) != 0, showButtons = (options & EditorListOptions.Buttons) != 0; for (int i = 0; i < list.arraySize; i++) { if (showButtons) { EditorGUILayout.BeginHorizontal(); // Forces buttons to stay on a single line, rather than vertically aligned } if (showElementLabels) { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i)); // Show each property at each index } else { EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), GUIContent.none); } if (showButtons) { ShowButtons(list, i); EditorGUILayout.EndHorizontal(); // ends the single line started above } } if (showButtons && list.arraySize == 0 && GUILayout.Button(addButtonContent, EditorStyles.miniButton)) { list.arraySize += 1; // Allows us to easily add a new array element } }
public static void Show(SerializedProperty list, EditorListOptions options = EditorListOptions.Default) { EditorGUI.indentLevel = 1; bool showListLabel = (options & EditorListOptions.ListLabel) != 0, // bitwise operations showListSize = (options & EditorListOptions.ListSize) != 0; if (showListLabel) { EditorGUILayout.PropertyField(list); EditorGUI.indentLevel += 1; // add indent level before showing elements } if (!showListLabel || list.isExpanded) // toggle for collapsed/expanded foldout in list { SerializedProperty size = list.FindPropertyRelative("Array.size"); // If editing multiple lists of different sizes, we want to unShow the list's elements to avoid errors if (showListSize) { EditorGUILayout.PropertyField(size); } if (size.hasMultipleDifferentValues) { EditorGUILayout.HelpBox("Not showing lists with different sizes.", MessageType.Info); } else { ShowElements(list, options); } } if (showListLabel) { EditorGUI.indentLevel -= 1; // reduce indent level after showing elements } }