Пример #1
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);
        }
Пример #2
0
        protected override InitState InitPropertyImpl(MightySerializedField serializedField, Ta attribute)
        {
            var property = serializedField.Property;

            if (!property.IsCollection())
            {
                return(new InitState(false, $"\"{property.displayName}\" should be an array"));
            }

            if (!serializedField.PropertyType.IsSubclassOf(typeof(To)))
            {
                return(new InitState(false, $"\"{property.displayName}\" array type should inherit from {typeof(To).FullName}"));
            }

            var objects = GetFoundArray(serializedField, attribute);

            if (property.CompareArrays(objects))
            {
                return(new InitState(true));
            }

            property.ClearArray();
            for (var i = 0; i < objects.Length; i++)
            {
                property.InsertArrayElementAtIndex(i);
                property.GetArrayElementAtIndex(i).objectReferenceValue = objects[i];
            }

            return(new InitState(true));
        }
Пример #3
0
 public void BeginDrawHeader(MightySerializedField serializedField, BaseArrayDecoratorAttribute baseAttribute)
 {
     if (PositionByMember(serializedField, baseAttribute).Contains(ArrayDecoratorPosition.BeforeHeader))
     {
         DrawDecorator(serializedField, (T)baseAttribute);
     }
 }
Пример #4
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property,
                                             GetComponentButtonAttribute attribute)
        {
            if (property.propertyType != SerializedPropertyType.ObjectReference ||
                !mightyMember.PropertyType.IsSubclassOf(typeof(Component)))
            {
                MightyGUIUtilities.DrawHelpBox($"{nameof(GetComponentButtonAttribute)} can be used only on Components fields");
                return;
            }

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.ObjectField(property, !attribute.Options.Contains(FieldOption.HideLabel)
                ? EditorGUIUtility.TrTextContent(property.displayName)
                : GUIContent.none);

            if (GUILayout.Button("Get Component", GUILayout.Width(100)))
            {
                var component = property.GetGameObject().GetComponent(mightyMember.PropertyType);
                if (component != null)
                {
                    property.objectReferenceValue = component;
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Пример #5
0
 public void EndDrawElement(MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute)
 {
     if (PositionByMember(serializedField, baseAttribute).Contains(ArrayDecoratorPosition.AfterElements))
     {
         DrawDecoratorElement(serializedField, index, (T)baseAttribute);
     }
 }
Пример #6
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, T attribute)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                MightyGUIUtilities.DrawPropertyField(property);
                MightyGUIUtilities.DrawHelpBox($"{attribute.GetType()} can be used only on string fields");
                return;
            }

            if (!m_pathCache.Contains(mightyMember))
            {
                EnableDrawer(mightyMember, attribute);
            }
            var defaultPath = m_pathCache[mightyMember].Value;

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PropertyField(property);
            if (MightyGUIUtilities.DrawButton("...", GUILayout.Width(35)))
            {
                var value = property.stringValue;

                value = DisplayPanel(property.displayName, !string.IsNullOrWhiteSpace(value)
                    ? FileUtilities.GetDirectoryPath(value) ?? value
                    : defaultPath, mightyMember, attribute);

                if (!string.IsNullOrWhiteSpace(value))
                {
                    property.stringValue = value;
                }
            }

            EditorGUILayout.EndHorizontal();
        }
Пример #7
0
        protected override void ValidateProperty(MightySerializedField serializedField, MaxValueAttribute attribute)
        {
            var property = serializedField.Property;

            switch (property.propertyType)
            {
            case SerializedPropertyType.Integer:
                if (property.intValue > attribute.MaxValue)
                {
                    property.intValue = (int)attribute.MaxValue;
                }
                break;

            case SerializedPropertyType.Float:
                if (property.floatValue > attribute.MaxValue)
                {
                    property.floatValue = attribute.MaxValue;
                }
                break;

            default:
                MightyGUIUtilities.DrawHelpBox($"{nameof(MaxValueAttribute)} can be used only on int or float fields");
                break;
            }
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
0
 public override void EndDrawMember(MightySerializedField serializedField, T attribute,
                                    MightyDrawer.PropertyDrawCallback propertyDrawCallback, BasePropertyDrawerAttribute drawerAttribute = null)
 {
     if (!serializedField.Property.IsCollection())
     {
         EndLayout(serializedField, attribute);
     }
 }
Пример #11
0
        protected override void DrawProperty(MightySerializedField serializedField, SerializedProperty property,
                                             CustomDrawerAttribute attribute)
        {
            GetDrawerForMember(serializedField, m_propertyCallback, out var drawerMethod, attribute);

            InvokeDrawer(drawerMethod,
                         $"void {attribute.DrawerCallback}(MightySerializedField serializedField)",
                         serializedField);
        }
Пример #12
0
        public Rect EndDrawElement(Rect rect, MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute)
        {
            if (PositionByMember(serializedField, baseAttribute).Contains(ArrayDecoratorPosition.AfterElements))
            {
                rect = DrawDecoratorElement(rect, serializedField, index, (T)baseAttribute);
            }

            return(rect);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property, Rotation2DAttribute attribute)
        {
            if (property.IsCollection())
            {
                MightyGUIUtilities.DrawArray(property, index => DrawElement(mightyMember, index, attribute));
                return;
            }

            DrawRotation2D(property, attribute);
        }
Пример #16
0
        public void DrawElement(GUIContent label, MightySerializedField serializedField, int index, BasePropertyDrawerAttribute baseAttribute)
        {
            var attribute = (CustomDrawerAttribute)baseAttribute;

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

            InvokeDrawer(drawerMethod,
                         $"void {attribute.DrawerCallback}(GUIContent label, MightySerializedField serializedField, int index)",
                         label, serializedField, index);
        }
Пример #17
0
        public static void CacheArrayDrawerForField(this MightySerializedField serializedField, FieldInfo fieldInfo,
                                                    IEnumerable <BaseMightyAttribute> wrappedAttributes)
        {
            if (serializedField.CacheSingleAttribute <BaseArrayAttribute>(fieldInfo.GetCustomAttributes <BaseArrayAttribute>(true)))
            {
                return;
            }

            serializedField.CacheSingleAttribute <BaseArrayAttribute>(wrappedAttributes);
        }
Пример #18
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);
        }
Пример #19
0
        void IArrayDecoratorDrawer.EndDrawElement(MightySerializedField serializedField, int index,
                                                  BaseArrayDecoratorAttribute baseAttribute)
        {
            var decoratorPosition = PositionByMember(serializedField, baseAttribute);

            if (decoratorPosition.Contains(ArrayDecoratorPosition.After | ArrayDecoratorPosition.AfterElements))
            {
                DrawDecoratorElement(serializedField, index, (ShowAssetPreviewAttribute)baseAttribute);
            }
        }
Пример #20
0
        protected override void DrawProperty(MightySerializedField serializedField, SerializedProperty property,
                                             AssetOnlyAttribute attribute)
        {
            if (property.IsCollection())
            {
                MightyGUIUtilities.DrawArray(property, index => DrawElement(serializedField, index, attribute));
                return;
            }

            DrawAssetField(property, attribute);
        }
Пример #21
0
        protected override void DrawProperty(MightySerializedField mightyMember, SerializedProperty property,
                                             ResizableTextAreaAttribute attribute)
        {
            if (property.IsCollection())
            {
                MightyGUIUtilities.DrawArray(property, index => DrawElement(mightyMember, index, attribute));
                return;
            }

            DrawTextArea(property, attribute.Options);
        }
Пример #22
0
        public void EndDrawHeader(MightySerializedField serializedField, BaseArrayDecoratorAttribute baseAttribute)
        {
            var position = PositionByMember(serializedField, baseAttribute);

            if (position.Contains(ArrayDecoratorPosition.AfterHeader) ||
                position.Contains(ArrayDecoratorPosition.AfterHeaderFoldout) && serializedField.IsExpanded &&
                serializedField.ArraySize > 0)
            {
                DrawDecorator(serializedField, (T)baseAttribute);
            }
        }
Пример #23
0
        protected override void EndChangeCheck(bool changed, MightySerializedField mightyMember, LogOnChangedAttribute attribute)
        {
            if (!changed)
            {
                return;
            }
            var property = mightyMember.Property;

            Debug.Log($@"{property.displayName}: {PropertyUtilities.GetGenericValue(attribute.Target, property)}",
                      mightyMember.Context.Object);
        }
Пример #24
0
        Rect IArrayDecoratorDrawer.BeginDrawElement(Rect position, MightySerializedField serializedField, int index,
                                                    BaseArrayDecoratorAttribute baseAttribute)
        {
            var decoratorPosition = PositionByMember(serializedField, baseAttribute);

            if (decoratorPosition.Contains(ArrayDecoratorPosition.Before | ArrayDecoratorPosition.BeforeElements))
            {
                position = DrawDecoratorElement(position, serializedField, index, (ShowAssetPreviewAttribute)baseAttribute);
            }

            return(position);
        }
Пример #25
0
        protected override float GetDecoratorHeight(MightySerializedField serializedField, int index, ShowAssetPreviewAttribute attribute)
        {
            var element = serializedField.GetElement(index);

            Texture2D preview;

            if (element.propertyType != SerializedPropertyType.ObjectReference || element.objectReferenceValue == null ||
                (preview = AssetPreview.GetAssetPreview(element.objectReferenceValue)) == null)
            {
                return(40);
            }
            return(GetClampedWidthAndHeight(preview.width, preview.height, attribute.Size).Item2 +
                   MightyGUIUtilities.FIELD_SPACING);
        }
Пример #26
0
        public static void CacheValidatorsForField(this MightySerializedField serializedField, FieldInfo fieldInfo,
                                                   IEnumerable <BaseMightyAttribute> wrappedAttributes)
        {
            var validatorAttributes = new List <BaseValidatorAttribute>();

            var any = PopulateAttributesList(validatorAttributes, fieldInfo.GetCustomAttributes <BaseValidatorAttribute>(true));

            any = PopulateAttributesList(validatorAttributes, wrappedAttributes) || any;

            if (any)
            {
                serializedField.SetAttributes(validatorAttributes.ToArray());
            }
        }
Пример #27
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);
        }
Пример #28
0
        protected override void EnableSerializeFieldDrawer(MightySerializedField serializedField, CustomDrawerAttribute attribute)
        {
            var target = attribute.Target;

            if (!serializedField.Property.IsCollection())
            {
                InitCallback(serializedField, target, attribute.DrawerCallback, m_propertyCallback);
            }
            else
            {
                InitCallback(serializedField, target, attribute.DrawerCallback, m_elementCallback);
                InitCallback(serializedField, target, attribute.DrawerCallback, m_labeledElementCallback);
                InitCallback(serializedField, target, attribute.DrawerCallback, m_rectElementCallback);
                InitCallback(serializedField, target, attribute.ElementHeightCallback, m_elementHeightCallback);
            }
        }
Пример #29
0
        public void BeginDrawElement(MightySerializedField serializedField, int index, BaseArrayDecoratorAttribute baseAttribute)
        {
            var attribute = (T)baseAttribute;

            var position = PositionByMember(serializedField, attribute);

            if (position.Contains(ArrayDecoratorPosition.BeforeElements))
            {
                DrawDecoratorElement(serializedField, index, attribute);
            }

            if (index != 0 && position.Contains(ArrayDecoratorPosition.BetweenElements))
            {
                DrawDecoratorElement(serializedField, index, attribute);
            }
        }
Пример #30
0
        protected override void EnableSerializeFieldDrawer(MightySerializedField serializedField, T attribute)
        {
            if (serializedField.Property.propertyType != SerializedPropertyType.String)
            {
                return;
            }


            if (!attribute.PathAsCallback ||
                !serializedField.GetInfoFromMember <string>(attribute.Target, attribute.DefaultPath, out var pathInfo))
            {
                pathInfo = new MightyInfo <string>(attribute.DefaultPath ?? Application.dataPath);
            }

            m_pathCache[serializedField] = pathInfo;
        }