public void DrawField(string fieldName, Object context, object target)
        {
            var field     = target.GetField(fieldName);
            var attribute = field.GetCustomAttribute <EditorSerializeAttribute>();

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

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

            Deserialize(attribute, editorField, target, field, ref value);

            EditorGUI.BeginChangeCheck();

            value = EditorDrawUtility.DrawLayoutField(field, context, target, value,
                                                      !attribute.Options.Contains(EditorFieldOption.DontFold), attribute.Options.Contains(EditorFieldOption.Asset));

            if (EditorGUI.EndChangeCheck())
            {
                Serialize(attribute, editorField, value, field.FieldType);
            }
        }
        public void Serialize(object value, Type type)
        {
            var wrapper = EditorSerializedFieldUtilities.GetWrapperForType(type);

            if (wrapper != null)
            {
//                if (type.IsEnum)
//                    value = Enum.ToObject(type, value);
                Serialize(wrapper, value);
                return;
            }

            if (type.GetCustomAttribute(typeof(SerializableAttribute), true) == null)
            {
                return;
            }

            wrapper = EditorSerializedFieldUtilities.GetWrapperForType(typeof(bool));
            wrapper.SetValue(MightyGUIUtilities.GetFoldout(m_fileName));

            WriteFile(m_path, wrapper);

            foreach (var field in type.GetSerializableFields())
            {
                EditorFieldsDatabase.GetEditorField(m_fileName).Serialize(field.GetValue(value), field.FieldType);
            }
        }
        public void DrawField(string fieldName, Object context, object target, DrawCallback drawCallback)
        {
            var field     = target.GetField(fieldName);
            var attribute = field.GetCustomAttribute <EditorSerializeAttribute>();

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

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

            if (editorField == null)
            {
                return;
            }

            var value = field.GetValue(target);

            Deserialize(editorField, target, field, ref value);

            EditorGUI.BeginChangeCheck();

            value = drawCallback(attribute, context, target, value);

            if (EditorGUI.EndChangeCheck())
            {
                Serialize(attribute, editorField, value, field.FieldType);
            }
        }
        public static void ApplyEditorFieldChanges(this FieldInfo field, Object context, object target, string oldName = null)
        {
            if (oldName != null)
            {
                EditorFieldsDatabase.RenameField(context, oldName, field.Name);
            }

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

            editorField.Serialize(field.GetValue(target), field.FieldType);
        }
        public static void GetEditorFieldValue(this FieldInfo field, Object context, object target, out object value, string oldName = null)
        {
            if (oldName != null)
            {
                EditorFieldsDatabase.RenameField(context, oldName, field.Name);
            }

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

            editorField.DeserializeOverwrite(field.FieldType, out value);
        }
        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);
            }
        public override void DrawField(MightyMember <FieldInfo> mightyMember, BaseDrawerAttribute baseAttribute)
        {
            var attribute = (EditorSerializeAttribute)baseAttribute;
            var context   = mightyMember.Context;
            var field     = mightyMember.MemberInfo;
            var target    = mightyMember.Target;

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

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

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

            if (attribute.Options.Contains(EditorFieldOption.Deserialize))
            {
                Deserialize(attribute, 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 &&
                (DrawersDatabase.GetDrawerForAttribute <CustomDrawerPropertyDrawer>(typeof(CustomDrawerAttribute)) is var drawer))
            {
                value = drawer.DrawField(field, context, value, drawerAttribute);
            }
        public bool DeserializeOverwrite(Type type, out object value)
        {
            var wrapper = EditorSerializedFieldUtilities.GetWrapperForType(type);

            if (wrapper != null)
            {
                return(Deserialize(wrapper, out value));
            }

            value = null;

            if (type.GetCustomAttribute(typeof(SerializableAttribute), true) == null)
            {
                return(false);
            }

            if (!Exists())
            {
                return(false);
            }

            wrapper = EditorSerializedFieldUtilities.GetWrapperForType(typeof(bool));
            ReadFile(m_path, wrapper);
            wrapper.GetValue(out var foldout);
            MightyGUIUtilities.SetFoldout(m_fileName, (bool)foldout);

            value = Activator.CreateInstance(type);
            foreach (var field in type.GetSerializableFields())
            {
                EditorFieldsDatabase.GetEditorField(m_fileName).DeserializeOverwrite(field.FieldType, out var fieldValue);
                if (field.FieldType.IsEnum)
                {
                    fieldValue = Enum.ToObject(field.FieldType, fieldValue);
                }
                field.SetValue(value, fieldValue);
            }

            return(true);
        }