Exemple #1
0
 private static void DrawNonSerializedField(MightyNonSerializedField nonSerializedField)
 {
     DrawMember(nonSerializedField, true, (member, canDrawMember) =>
     {
         if (canDrawMember && member.TryGetAttribute(out BaseNonSerializedFieldAttribute attribute))
         {
             ((INonSerializedFieldDrawer)attribute.Drawer).DrawField((MightyNonSerializedField)member, attribute);
         }
     });
        public static void CacheNonSerializedDrawerForField(this MightyNonSerializedField nonSerializedField, FieldInfo fieldInfo,
                                                            IEnumerable <BaseMightyAttribute> wrappedAttributes)
        {
            if (nonSerializedField.CacheSingleAttribute <BaseNonSerializedFieldAttribute>(
                    fieldInfo.GetCustomAttributes <BaseNonSerializedFieldAttribute>(true)))
            {
                return;
            }

            nonSerializedField.CacheSingleAttribute <BaseNonSerializedFieldAttribute>(wrappedAttributes);
        }
        protected override void DrawField(MightyNonSerializedField nonSerializedField, EditorSerializeAttribute attribute)
        {
            var context = nonSerializedField.Context.Object;
            var field   = nonSerializedField.MemberInfo;
            var target  = nonSerializedField.Context.Target;

            if (attribute.PreviousName != null)
            {
                EditorFieldsDatabase.RenameField(context, attribute.PreviousName, field.Name);
            }

            if (attribute.Options == EditorFieldOption.Hide)
            {
                return;
            }

            var editorField = EditorFieldsDatabase.GetEditorField(context, field.Name);

            if (editorField == null)
            {
                return;
            }

            var value = field.GetValue(target);

            if (attribute.Options.Contains(EditorFieldOption.Deserialize))
            {
                Deserialize(editorField, target, field, ref value);
            }

            if (attribute.Options.Contains(EditorFieldOption.Hide) &&
                field.GetCustomAttribute(typeof(HideAttribute), true) is HideAttribute)
            {
                if (attribute.Options.Contains(EditorFieldOption.Serialize))
                {
                    Serialize(attribute, editorField, value, field.FieldType);
                }
                return;
            }

            if (attribute.Options.Contains(EditorFieldOption.Hide))
            {
                return;
            }

            EditorGUI.BeginChangeCheck();

            if (field.GetCustomAttribute(typeof(CustomDrawerAttribute), true) is CustomDrawerAttribute drawerAttribute &&
                MightyDrawersDatabase.GetDrawerForAttribute <CustomDrawerDrawer>(typeof(CustomDrawerAttribute)) is var drawer)
            {
                value = drawer.DrawField(field, context, value, drawerAttribute);
            }
Exemple #4
0
        protected override void DrawField(MightyNonSerializedField nonSerializedField, ShowNonSerializedAttribute attribute)
        {
            var field = nonSerializedField.MemberInfo;

            if (!m_showNonSerializedCache.Contains(nonSerializedField))
            {
                EnableDrawer(nonSerializedField, attribute);
            }
            var value = m_showNonSerializedCache[nonSerializedField].Value;

            if (MightyGUIUtilities.DrawLayoutField(attribute.DrawPrettyName ? field.Name.GetPrettyName() : field.Name, value,
                                                   nonSerializedField.MemberInfo.FieldType, attribute.Enabled))
            {
                return;
            }

            MightyGUIUtilities.DrawHelpBox($"{nameof(ShowNonSerializedAttribute)} doesn't support the type {field.FieldType.Name}");
        }