예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 private string SetFileName(string fieldName)
 {
     m_fileName = $"{m_guid}.{m_localId}.{fieldName}";
     return(EditorSerializedFieldUtilities.CreateEditorFieldPath(m_fileName));
 }