Example #1
0
        public void DeserializeDataIntoTarget(object target, SerializationData data)
        {
            var members = Logic.GetCachedSerializableMembers(target.GetType());

            for (int i = 0; i < members.Count; i++)
            {
                var member    = members[i];
                var memberKey = GetMemberKey(member);
                member.Target = target;

                try
                {
                    string result;
                    if (data.serializedStrings.TryGetValue(memberKey, out result))
                    {
                        var value = Deserialize(member.Type, result, data.serializedObjects);
                        member.Value = value;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("Error deserializing member {0} ({1}) in {2}: {3}. Stacktrace: {4}"
                                   .FormatWith(member.Name, member.Type.GetNiceName(), target, e.Message, e.StackTrace));
                }
            }
        }
        public void DeseiralizeDataIntoTarget(object target, SerializationData data)
        {
            var members = Logic.GetMemoizedSerializableMembers(target.GetType());

            for (int i = 0; i < members.Count; i++)
            {
                var member    = members[i];
                var memberKey = GetMemberKey(member);
                member.Target = target;

                try
                {
                    string result;
                    if (data.serializedStrings.TryGetValue(memberKey, out result))
                    {
                        var value = Deserialize(member.Type, result, data.serializedObjects);
                        member.Value = value;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError("Deserialization error: " + e.Message + " | " + e.StackTrace);
                }
            }
        }
Example #3
0
        public void SerializeTargetIntoData(object target, SerializationData data)
        {
            var members = Logic.GetCachedSerializableMembers(target.GetType());

            for (int i = 0; i < members.Count; i++)
            {
                var member = members[i];
                member.Target = target;
                var value = member.Value;

                if (value.IsObjectNull())
                {
                    continue;
                }

                try
                {
                    string memberKey       = GetMemberKey(member);
                    string serializedState = Serialize(member.Type, value, data.serializedObjects);
                    data.serializedStrings[memberKey] = serializedState;
                }
                catch (Exception e)
                {
                    Debug.LogError("Error serializing member {0} ({1}) in {2}: {3}. Stacktrace: {4}"
                                   .FormatWith(member.Name, member.Type.GetNiceName(), target, e.Message, e.StackTrace));
                }
            }
        }
        public void SerializeTargetIntoData(object target, SerializationData data)
        {
            var members = Logic.GetMemoizedSerializableMembers(target.GetType());

            for (int i = 0; i < members.Count; i++)
            {
                var member = members[i];
                member.Target = target;
                var value = member.Value;

                if (value.IsObjectNull())
                {
                    continue;
                }

                try
                {
                    string memberKey       = GetMemberKey(member);
                    string serializedState = Serialize(member.Type, value, data.serializedObjects);
                    data.serializedStrings[memberKey] = serializedState;
                }
                catch (Exception e)
                {
                    Debug.LogError("Serialization error: " + e.Message + " | " + e.StackTrace);
                }
            }
        }
        /// <summary>
        /// Fetches the serialized state of the specified target from the specified serialization data
        /// to use it to deserialize/reload the target reassigning all the target's member values
        /// </summary>
        public void DeserializeTargetFromData(UnityObject target, SerializationData data)
        {
            var members = VFWSerializationLogic.Instance.CachedGetSerializableMembers(target.GetType());

            for (int i = 0; i < members.Length; i++)
            {
                var member    = members[i];
                var memberKey = GetMemberKey(member);
                member.Target = target;

                ConvertLegacyKeys(data);

                try
                {
                    string result;
                    if (data.serializedStrings.TryGetValue(memberKey, out result))
                    {
                        var value = Deserialize(member.Type, result, data.serializedObjects);
                        member.Value = value;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(
                        "Error deserializing member `" + member.Name + "` (" + member.Type.Name + ")" +
                        " in `" + target.GetType().Name +
                        "` Error message: \"" + e.Message +
                        "\" Stacktrace: " + e.StackTrace);
                }
            }
        }
        /// <summary>
        /// Serializes the specified target and stores the result in the specified serialization data
        /// such that all Unity object references are stored in the data's serializedObjects list,
        /// and the serializable members' values in the data's serializedStrings
        /// </summary>
        public void SerializeTargetIntoData(UnityObject target, SerializationData data)
        {
            data.Clear();

            var members = VFWSerializationLogic.Instance.CachedGetSerializableMembers(target.GetType());

            for (int i = 0; i < members.Length; i++)
            {
                var member = members[i];
                member.Target = target;
                var value = member.Value;

                try
                {
                    string memberKey       = GetMemberKey(member);
                    string serializedState = Serialize(member.Type, value, data.serializedObjects);
                    data.serializedStrings[memberKey] = serializedState;
                }
                catch (Exception e)
                {
                    Debug.LogError(
                        "Error serializing member `" + member.Name + "` (" + member.Type.Name + ")" +
                        " in `" + target.GetType().Name +
                        "` Error message: \"" + e.Message +
                        "\" Stacktrace: " + e.StackTrace);
                }
            }
        }
        /// <summary>
        /// Serializes the specified target and stores the result in the specified serialization data
        /// such that all Unity object references are stored in the data's serializedObjects list,
        /// and the serializable members' values in the data's serializedStrings
        /// </summary>
        public void SerializeTargetIntoData(object target, SerializationData data)
        {
            var members = Logic.CachedGetSerializableMembers(target.GetType());

            for (int i = 0; i < members.Count; i++)
            {
                var member = members[i];
                member.Target = target;
                var value = member.Value;

                if (value.IsObjectNull())
                {
                    continue;
                }

                try
                {
                    string memberKey       = GetMemberKey(member);
                    string serializedState = Serialize(member.Type, value, data.serializedObjects);
                    data.serializedStrings[memberKey] = serializedState;
                }
                catch (Exception e)
                {
                    Debug.LogError(
                        "Error serializing member `" + member.Name + "` (" + member.Type.Name + ")" +
                        " in `" + target.GetType().Name +
                        "` Error message: \"" + e.Message +
                        "\" Stacktrace: " + e.StackTrace);
                }
            }
        }
Example #8
0
        private static void ConvertLegacyKeys(SerializationData data)
        {
            var keys = data.serializedStrings.Keys;

            for (int i = 0; i < keys.Count; i++)
            {
                var key = keys[i];
                key     = key.Replace("Field: ", string.Empty);
                key     = key.Replace("Property: ", string.Empty);
                keys[i] = key;
            }
        }