Exemplo n.º 1
0
        public void DrawElement(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var attribute = (CustomDrawerAttribute)baseAttribute;

            GetDrawerForMember(serializedField, m_elementCallback, out var drawerMethod, attribute);

            InvokeDrawer(drawerMethod,
                         $"void {attribute.DrawerCallback}(MightySerializedField serializedField, int index)",
                         serializedField, index);
        }
Exemplo n.º 2
0
 private bool GetDrawerForMember(BaseMightyMember member, CallbackSignature signature, out MightyMethod <object> drawerMethod,
                                 BasePropertyDrawerAttribute attribute)
 {
     if (GetDrawerForMember(member.ID, signature, out drawerMethod))
     {
         return(true);
     }
     EnableDrawer(member, attribute);
     return(GetDrawerForMember(member.ID, signature, out drawerMethod));
 }
Exemplo n.º 3
0
        private float GetElementHeight(MightySerializedField serializedField, ReorderableListAttribute attribute,
                                       IArrayElementDrawer drawer, BasePropertyDrawerAttribute drawerAttribute, int index)
        {
            var decoratorAttributes = GetDecorationsForMember(serializedField, attribute);

            var height = drawer?.GetElementHeight(serializedField, index, drawerAttribute) ??
                         MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING;

            foreach (var decoratorAttribute in decoratorAttributes)
            {
                height += ((IArrayDecoratorDrawer)decoratorAttribute.Drawer).GetElementHeight(serializedField, index, decoratorAttribute);
            }

            return(height + 2);
        }
Exemplo n.º 4
0
        public void DrawArray(MightySerializedField serializedField, T attribute, IArrayElementDrawer drawer,
                              BasePropertyDrawerAttribute drawerAttribute)
        {
            var property = serializedField.Property;

            if (!property.IsCollection())
            {
                MightyGUIUtilities.DrawHelpBox($"{attribute.GetType().Name} can be used only on arrays or lists");

                MightyGUIUtilities.DrawPropertyField(property);
                return;
            }

            var options = GetOptionsForMember(serializedField, attribute);

            var decoratorAttributes = GetDecorationsForMember(serializedField, attribute);

            DrawArrayImpl(serializedField, attribute, options, decoratorAttributes, drawer, drawerAttribute);
        }
Exemplo n.º 5
0
 public void DrawElement(Rect position, MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
 => DrawAssetField(position, serializedField.GetElement(index), (AssetOnlyAttribute)baseAttribute);
Exemplo n.º 6
0
 public void DrawElement(GUIContent label, MightySerializedField serializedField, int index,
                         BasePropertyDrawerAttribute baseAttribute) =>
 DrawAssetField(serializedField.GetElement(index), (AssetOnlyAttribute)baseAttribute, label);
Exemplo n.º 7
0
        public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var propertyType = serializedField.GetElement(index).propertyType;

            return(propertyType != SerializedPropertyType.Integer && propertyType != SerializedPropertyType.Float
                ? MightyGUIUtilities.WARNING_HEIGHT
                : MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING);
        }
Exemplo n.º 8
0
        public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var attribute         = (CustomDrawerAttribute)baseAttribute;
            var elementHeightName = attribute.ElementHeightCallback;

            if (string.IsNullOrWhiteSpace(elementHeightName))
            {
                return(0);
            }

            if (GetDrawerForMember(serializedField, m_elementHeightCallback, out var callback, attribute))
            {
                return((float)callback.Invoke(serializedField, index));
            }

            MightyGUIUtilities.DrawHelpBox(
                $"Element height is invalid, it should be like this: \"float {elementHeightName}(MightySerializedField serializedField, int index)\"");
            return(0);
        }
Exemplo n.º 9
0
        public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var element = serializedField.GetElement(index);

            return(element.propertyType != SerializedPropertyType.String
                ? MightyGUIUtilities.WARNING_HEIGHT
                : MightyGUIUtilities.TextHeight(element.stringValue, 3) + MightyGUIUtilities.FIELD_HEIGHT +
                   MightyGUIUtilities.FIELD_SPACING * 2);
        }
Exemplo n.º 10
0
 public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) =>
 serializedField.GetElement(index).propertyType != SerializedPropertyType.Quaternion
         ? MightyGUIUtilities.WARNING_HEIGHT
         : MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING;
Exemplo n.º 11
0
 public void DrawElement(GUIContent label, MightySerializedField serializedField, int index,
                         BasePropertyDrawerAttribute baseAttribute) =>
 DrawRotation2D(serializedField.GetElement(index), (Rotation2DAttribute)baseAttribute, label);
Exemplo n.º 12
0
        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();
        }
Exemplo n.º 13
0
        public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var element = serializedField.GetElement(index);

            return(element.propertyType != SerializedPropertyType.ObjectReference
                ? MightyGUIUtilities.WARNING_HEIGHT
                : !AssetPreview.GetAssetPreview(element.objectReferenceValue)
                    ? MightyGUIUtilities.FIELD_HEIGHT + MightyGUIUtilities.FIELD_SPACING
                    : 64);
        }
Exemplo n.º 14
0
 public void DrawElement(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) =>
 DrawLayerField(serializedField.GetElement(index), (LayerFieldAttribute)baseAttribute);
Exemplo n.º 15
0
 public override void EndDrawMember(MightySerializedField serializedField, T attribute,
                                    MightyDrawer.PropertyDrawCallback propertyDrawCallback, BasePropertyDrawerAttribute drawerAttribute = null)
 {
     if (!serializedField.Property.IsCollection())
     {
         EndLayout(serializedField, attribute);
     }
 }
Exemplo n.º 16
0
        protected override void BeginDrawMember(MightySerializedField serializedField, T attribute,
                                                MightyDrawer.PropertyDrawCallback propertyDrawCallback = null, BasePropertyDrawerAttribute drawerAttribute = null)
        {
            var property = serializedField.Property;

            if (property.IsCollection())
            {
                MightyGUIUtilities.DrawArray(property, index =>
                {
                    BeginDrawElement(serializedField, index, attribute);
                    propertyDrawCallback?.Invoke(serializedField, property, drawerAttribute);
                    EndDrawElement(serializedField, index, attribute);
                });
                return;
            }

            BeginLayout(serializedField, attribute);
            propertyDrawCallback?.Invoke(serializedField, property, drawerAttribute);
        }
Exemplo n.º 17
0
 public void DrawElement(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute) =>
 DrawTagField(serializedField.GetElement(index), baseAttribute.Options);
Exemplo n.º 18
0
 public void DrawProperty(MightySerializedField serializedField, SerializedProperty property, BasePropertyDrawerAttribute attribute)
 => DrawProperty(serializedField, property, (T)attribute);
Exemplo n.º 19
0
 public void DrawArray(MightySerializedField serializedField, BaseArrayAttribute attribute,
                       IArrayElementDrawer drawerAttributeDrawer, BasePropertyDrawerAttribute drawerAttribute) =>
 DrawArray(serializedField, (T)attribute, drawerAttributeDrawer, drawerAttribute);
Exemplo n.º 20
0
        protected virtual void BeginDrawMember(MightySerializedField serializedField, T attribute,
                                               MightyDrawer.PropertyDrawCallback propertyDrawCallback = null, BasePropertyDrawerAttribute drawerAttribute = null)
        {
            var property = serializedField.Property;

            if (!property.IsCollection())
            {
                BeginDraw(serializedField, attribute);

                propertyDrawCallback?.Invoke(serializedField, property, drawerAttribute);
                return;
            }

            BeginDrawArray(serializedField, attribute);
            BeginDrawHeader(serializedField, attribute);

            if (!MightyGUIUtilities.DrawFoldout(property))
            {
                EndDrawHeader(serializedField, attribute);
                EndDrawArray(serializedField, attribute);
                return;
            }

            EditorGUI.indentLevel++;
            MightyGUIUtilities.DrawArraySizeField(property);

            EndDrawHeader(serializedField, attribute);
        }
Exemplo n.º 21
0
 protected abstract void DrawArrayImpl(MightySerializedField serializedField, T attribute, ArrayOption options,
                                       BaseArrayDecoratorAttribute[] decoratorAttributes, IArrayElementDrawer drawer, BasePropertyDrawerAttribute drawerAttribute);
Exemplo n.º 22
0
        public virtual void EndDrawMember(MightySerializedField serializedField, T attribute,
                                          MightyDrawer.PropertyDrawCallback propertyDrawCallback, BasePropertyDrawerAttribute drawerAttribute = null)
        {
            var property = serializedField.Property;

            if (!property.IsCollection())
            {
                EndDraw(serializedField, attribute);
                return;
            }

            if (!property.isExpanded)
            {
                return;
            }

            MightyGUIUtilities.DrawArrayBody(property, index =>
            {
                BeginDrawElement(serializedField, index, attribute);
                propertyDrawCallback?.Invoke(serializedField, property.GetArrayElementAtIndex(index), drawerAttribute);
                EndDrawElement(serializedField, index, attribute);
            });

            EditorGUI.indentLevel--;

            EndDrawArray(serializedField, attribute);
        }
Exemplo n.º 23
0
 public void DrawElement(Rect position, MightySerializedField serializedField, int index,
                         BasePropertyDrawerAttribute baseAttribute) =>
 DrawRotation2D(position, serializedField.GetElement(index), (Rotation2DAttribute)baseAttribute);
Exemplo n.º 24
0
 public void EndDrawMember(MightySerializedField serializedField, BaseArrayDecoratorAttribute baseAttribute,
                           MightyDrawer.PropertyDrawCallback propertyDrawCallback = null, BasePropertyDrawerAttribute drawerAttribute = null) =>
 EndDrawMember(serializedField, (T)baseAttribute, propertyDrawCallback, drawerAttribute);
Exemplo n.º 25
0
 public void DrawElement(GUIContent label, MightySerializedField serializedField, int index,
                         BasePropertyDrawerAttribute baseAttribute) => DrawField(serializedField.GetElement(index), baseAttribute.Options, label);
Exemplo n.º 26
0
 public void DrawElement(Rect position, MightySerializedField serializedField, int index,
                         BasePropertyDrawerAttribute baseAttribute) => DrawField(position, serializedField.GetElement(index), baseAttribute.Options);
Exemplo n.º 27
0
        public void DrawElement(Rect position, MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var attribute = (CustomDrawerAttribute)baseAttribute;

            GetDrawerForMember(serializedField, m_rectElementCallback, out var drawerMethod, attribute);

            InvokeDrawer(position, drawerMethod,
                         $"Rect {attribute.DrawerCallback}(Rect position, MightySerializedField serializedField, int index)",
                         position, serializedField, index);
        }
Exemplo n.º 28
0
 public float GetElementHeight(MightySerializedField serializedField, int index, BasePropertyDrawerAttribute attribute) =>
 IsPropertyTypeValid(serializedField.GetElement(index).propertyType)
         ? GetFieldHeight(attribute.Options)
         : MightyGUIUtilities.WARNING_HEIGHT;
Exemplo n.º 29
0
        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);
            }
        }
Exemplo n.º 30
0
 public void DrawElement(Rect position, MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
 => DrawSlider(position, serializedField.GetElement(index), (PercentSliderAttribute)baseAttribute);