protected override void DrawArrayImpl(MightySerializedField serializedField, ButtonArrayAttribute attribute, ArrayOption options, BaseArrayDecoratorAttribute[] decoratorAttributes, IArrayElementDrawer drawer, BasePropertyDrawerAttribute drawerAttribute) { var property = serializedField.Property; foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).BeginDrawArray(serializedField, decoratorAttribute); } foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).BeginDrawHeader(serializedField, decoratorAttribute); } if (!options.Contains(ArrayOption.HideLabel)) { if (options.Contains(ArrayOption.DontFold)) { EditorGUILayout.LabelField(property.displayName, options.Contains(ArrayOption.BoldLabel) ? EditorStyles.boldLabel : EditorStyles.label); property.isExpanded = true; } else if (!MightyGUIUtilities.DrawFoldout(property, options.Contains(ArrayOption.BoldLabel) ? MightyStyles.BoldFoldout : null)) { foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawHeader(serializedField, decoratorAttribute); } foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawArray(serializedField, decoratorAttribute); } return; } } else { property.isExpanded = true; } if (!options.Contains(ArrayOption.DontIndent)) { EditorGUI.indentLevel++; } foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawHeader(serializedField, decoratorAttribute); } GUILayout.BeginVertical(MightyStyleUtilities.GetButtonArray(EditorGUI.indentLevel - 1), GUILayout.MinHeight(35)); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (property.arraySize == 0) { GUILayout.FlexibleSpace(); if (MightyGUIUtilities.DrawAddButton()) { property.InsertArrayElementAtIndex(0); property.serializedObject.ApplyModifiedProperties(); } GUILayout.FlexibleSpace(); } MightyGUIUtilities.DrawArrayBody(property, index => { var element = property.GetArrayElementAtIndex(index); foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).BeginDrawElement(serializedField, index, decoratorAttribute); } GUILayout.BeginHorizontal(GUILayout.MinHeight(33)); GUILayout.BeginVertical(GUILayout.Width(1)); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); if (MightyGUIUtilities.DrawRemoveButton()) { property.DeleteArrayElementAtIndex(index); property.serializedObject.ApplyModifiedProperties(); GUILayout.EndHorizontal(); foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawElement(serializedField, index, decoratorAttribute); } return; } if (MightyGUIUtilities.DrawAddButton()) { property.InsertArrayElementAtIndex(index); property.serializedObject.ApplyModifiedProperties(); } if (serializedField.IsFoldable()) { GUILayout.Space(10); } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); if (drawer != null) { drawer.DrawElement(serializedField, index, drawerAttribute); } else if (options.Contains(ArrayOption.HideElementLabel)) { EditorGUILayout.PropertyField(element, GUIContent.none); } else { EditorGUILayout.PropertyField(element); } GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawElement(serializedField, index, decoratorAttribute); } }); EditorGUI.indentLevel = indent; GUILayout.EndVertical(); if (!options.Contains(ArrayOption.DontIndent)) { EditorGUI.indentLevel--; } foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawArray(serializedField, decoratorAttribute); } }
public override void DrawArray(BaseMightyMember mightyMember, BaseArrayAttribute baseAttribute, IArrayElementDrawer drawer, BaseDrawerAttribute drawerAttribute) { var property = mightyMember.Property; if (!property.isArray) { EditorDrawUtility.DrawHelpBox($"{typeof(ButtonArrayAttribute).Name} can be used only on arrays or lists"); EditorDrawUtility.DrawPropertyField(property); return; } if (!ArrayCache.Contains(mightyMember)) { InitDrawer(mightyMember, baseAttribute); } var(optionInfo, decoratorAttributes, decoratorDrawers) = ArrayCache[mightyMember]; var option = optionInfo.Value; var decoratorLength = decoratorAttributes.Length; for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].BeginDrawArray(mightyMember, decoratorAttributes[i]); } for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].BeginDrawHeader(mightyMember, decoratorAttributes[i]); } if (!option.Contains(ArrayOption.HideLabel) && !EditorDrawUtility.DrawFoldout(property)) { for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawHeader(mightyMember, decoratorAttributes[i]); } for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawArray(mightyMember, decoratorAttributes[i]); } return; } if (option.Contains(ArrayOption.HideLabel)) { property.isExpanded = true; } else if (!option.Contains(ArrayOption.DontIndent)) { EditorGUI.indentLevel++; } for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawHeader(mightyMember, decoratorAttributes[i]); } GUILayout.BeginVertical(GUIStyleUtility.ButtonArray, GUILayout.MinHeight(35)); var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; if (property.arraySize == 0) { GUILayout.FlexibleSpace(); if (EditorDrawUtility.DrawAddButton()) { property.InsertArrayElementAtIndex(0); property.serializedObject.ApplyModifiedProperties(); } GUILayout.FlexibleSpace(); } EditorDrawUtility.DrawArrayBody(property, index => { var element = property.GetArrayElementAtIndex(index); for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].BeginDrawElement(mightyMember, index, decoratorAttributes[i]); } GUILayout.BeginHorizontal(GUILayout.MinHeight(33)); GUILayout.BeginVertical(GUILayout.Width(1)); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); if (EditorDrawUtility.DrawRemoveButton()) { property.DeleteArrayElementAtIndex(index); property.serializedObject.ApplyModifiedProperties(); GUILayout.EndHorizontal(); for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawElement(mightyMember, index, decoratorAttributes[i]); } return; } if (EditorDrawUtility.DrawAddButton()) { property.InsertArrayElementAtIndex(index); property.serializedObject.ApplyModifiedProperties(); } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.FlexibleSpace(); if (drawer != null) { drawer.DrawElement(mightyMember, index, drawerAttribute); } else if (option.Contains(ArrayOption.HideElementLabel)) { EditorGUILayout.PropertyField(element, GUIContent.none); } else { EditorGUILayout.PropertyField(element); } GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawElement(mightyMember, index, decoratorAttributes[i]); } }); EditorGUI.indentLevel = indent; GUILayout.EndVertical(); if (!option.Contains(ArrayOption.HideLabel) && !option.Contains(ArrayOption.DontIndent)) { EditorGUI.indentLevel--; } for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawArray(mightyMember, decoratorAttributes[i]); } }
public override void DrawArray(BaseMightyMember mightyMember, BaseArrayAttribute baseAttribute, IArrayElementDrawer drawer, BaseDrawerAttribute drawerAttribute) { var property = mightyMember.Property; if (property.isArray) { var attribute = (ReorderableListAttribute)baseAttribute; if (!ArrayCache.Contains(mightyMember)) { InitDrawer(mightyMember, baseAttribute); } var(optionInfo, decoratorAttributes, decoratorDrawers) = ArrayCache[mightyMember]; var option = optionInfo.Value; var decoratorLength = decoratorAttributes.Length; EditorGUILayout.BeginVertical(); for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].BeginDrawArray(mightyMember, decoratorAttributes[i]); } if (!option.Contains(ArrayOption.HideLabel)) { if (!option.Contains(ArrayOption.LabelInHeader)) { for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].BeginDrawHeader(mightyMember, decoratorAttributes[i]); } if (!EditorDrawUtility.DrawFoldout(property)) { EditorGUILayout.EndVertical(); for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawHeader(mightyMember, decoratorAttributes[i]); } for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawArray(mightyMember, decoratorAttributes[i]); } return; } for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawHeader(mightyMember, decoratorAttributes[i]); } } } else { property.isExpanded = true; } if (!option.Contains(ArrayOption.DontIndent)) { m_indentCache[mightyMember] = EditorGUI.indentLevel; EditorDrawUtility.BeginLayoutIndent(); EditorGUI.indentLevel = 0; EditorGUILayout.BeginVertical(); } if (!m_reorderableCache.Contains(mightyMember)) { ReorderableList reorderableList = new ReorderableList(property.serializedObject, property, !option.Contains(ArrayOption.ReadOnly), option.Contains(ArrayOption.LabelInHeader) || !option.Contains(ArrayOption.HideSizeField), attribute.DrawButtons, attribute.DrawButtons) { drawHeaderCallback = rect => { var drawLabel = option.Contains(ArrayOption.LabelInHeader); if (!drawLabel && option.Contains(ArrayOption.HideSizeField)) { return; } for (var i = 0; i < decoratorLength; i++) { rect = decoratorDrawers[i].BeginDrawHeader(rect, mightyMember, decoratorAttributes[i]); } if (!drawLabel) { var enabled = GUI.enabled; GUI.enabled = !option.Contains(ArrayOption.DisableSizeField); EditorDrawUtility.DrawArraySizeField(rect, property); GUI.enabled = enabled; } else { EditorGUI.LabelField(rect, property.displayName); } var newRect = new Rect(rect.x, rect.y + EditorGUIUtility.singleLineHeight, rect.width, 0); for (var i = 0; i < decoratorLength; i++) { newRect = decoratorDrawers[i].EndDrawHeader(newRect, mightyMember, decoratorAttributes[i]); } }, drawElementCallback = (rect, index, isActive, isFocused) => { rect.y += 2f; var newRect = new Rect(rect.x, rect.y + 21, rect.width, 0); for (var i = 0; i < decoratorLength; i++) { newRect = decoratorDrawers[i].BeginDrawElement(newRect, mightyMember, i, decoratorAttributes[i]); } if (drawer != null) { var height = drawer.GetElementHeight(mightyMember, index, drawerAttribute); drawer.DrawElement(new Rect(rect.x, rect.y, rect.width, height), mightyMember, index, drawerAttribute); } else { EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), property.GetArrayElementAtIndex(index)); } for (var i = 0; i < decoratorLength; i++) { newRect = decoratorDrawers[i].EndDrawElement(newRect, mightyMember, i, decoratorAttributes[i]); } }, elementHeightCallback = (index) => { var height = drawer?.GetElementHeight(mightyMember, index, drawerAttribute) ?? 20; for (var i = 0; i < decoratorLength; i++) { height += decoratorDrawers[i].GetElementHeight(mightyMember, i, decoratorAttributes[i]); } return(height); } }; m_reorderableCache[mightyMember] = reorderableList; } m_reorderableCache[mightyMember].DoLayoutList(); if (!option.Contains(ArrayOption.DontIndent)) { EditorGUI.indentLevel = m_indentCache[mightyMember]; EditorDrawUtility.EndLayoutIndent(); EditorGUILayout.EndVertical(); } for (var i = 0; i < decoratorLength; i++) { decoratorDrawers[i].EndDrawArray(mightyMember, decoratorAttributes[i]); } EditorGUILayout.EndVertical(); } else { EditorDrawUtility.DrawHelpBox($"{baseAttribute.GetType().Name} can be used only on arrays or lists"); EditorDrawUtility.DrawPropertyField(property); } }
protected override void DrawArrayImpl(MightySerializedField serializedField, ReorderableListAttribute attribute, ArrayOption options, BaseArrayDecoratorAttribute[] decoratorAttributes, IArrayElementDrawer drawer, BasePropertyDrawerAttribute drawerAttribute) { var property = serializedField.Property; EditorGUILayout.BeginVertical(); foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).BeginDrawArray(serializedField, decoratorAttribute); } if (!options.Contains(ArrayOption.HideLabel) && !options.Contains(ArrayOption.LabelInHeader)) { foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).BeginDrawHeader(serializedField, decoratorAttribute); } if (options.Contains(ArrayOption.DontFold)) { EditorGUILayout.LabelField(property.displayName, options.Contains(ArrayOption.BoldLabel) ? EditorStyles.boldLabel : EditorStyles.label); property.isExpanded = true; } else if (!MightyGUIUtilities.DrawFoldout(property, options.Contains(ArrayOption.BoldLabel) ? MightyStyles.BoldFoldout : null)) { EditorGUILayout.EndVertical(); foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawHeader(serializedField, decoratorAttribute); } foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawArray(serializedField, decoratorAttribute); } return; } foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawHeader(serializedField, decoratorAttribute); } } else { property.isExpanded = true; } if (!options.Contains(ArrayOption.DontIndent)) { m_indentCache[serializedField] = EditorGUI.indentLevel; MightyGUIUtilities.BeginLayoutIndent(); EditorGUI.indentLevel = 0; EditorGUILayout.BeginVertical(); } if (!m_reorderableCache.Contains(serializedField)) { ReorderableList reorderableList = new ReorderableList(property.serializedObject, property, attribute.Draggable, options.Contains(ArrayOption.LabelInHeader) || !options.Contains(ArrayOption.HideSizeField), attribute.DrawButtons, attribute.DrawButtons) { drawHeaderCallback = position => { var labelWidth = EditorGUIUtility.labelWidth; if (options.Contains(ArrayOption.LabelInHeader)) { var labelSpace = Screen.width - WIDTH_OVERFLOW - SIZE_FIELD_WIDTH - SIZE_LABEL_WIDTH; position.width = labelSpace - SPACE; if (options.Contains(ArrayOption.BoldLabel)) { EditorGUI.LabelField(position, property.displayName, EditorStyles.boldLabel); } else { EditorGUI.LabelField(position, property.displayName); } position.x = labelSpace; position.width = SIZE_FIELD_WIDTH + SIZE_LABEL_WIDTH; EditorGUIUtility.labelWidth = SIZE_LABEL_WIDTH; } if (!options.Contains(ArrayOption.HideSizeField)) { var enabled = GUI.enabled; GUI.enabled = !options.Contains(ArrayOption.DisableSizeField); MightyGUIUtilities.DrawArraySizeField(position, property); GUI.enabled = enabled; } EditorGUIUtility.labelWidth = labelWidth; }, drawElementCallback = (position, index, isActive, isFocused) => { position.y += 2; foreach (var decoratorAttribute in decoratorAttributes) { position = ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).BeginDrawElement(position, serializedField, index, decoratorAttribute); } if (drawer != null) { var height = drawer.GetElementHeight(serializedField, index, drawerAttribute); position.height = height; drawer.DrawElement(position, serializedField, index, drawerAttribute); position = MightyGUIUtilities.JumpHeight(position, height); } else if (options.Contains(ArrayOption.HideElementLabel)) { position = MightyGUIUtilities.DrawPropertyField(position, property.GetArrayElementAtIndex(index), GUIContent.none); } else { position = MightyGUIUtilities.DrawPropertyField(position, property.GetArrayElementAtIndex(index)); } foreach (var decoratorAttribute in decoratorAttributes) { position = ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawElement(position, serializedField, index, decoratorAttribute); } }, elementHeightCallback = index => GetElementHeight(serializedField, attribute, drawer, drawerAttribute, index), headerHeight = MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING }; m_reorderableCache[serializedField] = reorderableList; } m_reorderableCache[serializedField].DoLayoutList(); if (!options.Contains(ArrayOption.DontIndent)) { EditorGUI.indentLevel = m_indentCache[serializedField]; MightyGUIUtilities.EndLayoutIndent(); EditorGUILayout.EndVertical(); } foreach (var decoratorAttribute in decoratorAttributes) { ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).EndDrawArray(serializedField, decoratorAttribute); } EditorGUILayout.EndVertical(); }