Example #1
0
        /// <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(IVFWObject target)
        {
            var data    = target.GetSerializationData();
            var members = target.GetSerializedMembers();

            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);
                }
            }
        }
Example #2
0
        /// <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(IVFWObject target)
        {
            var data = target.GetSerializationData();

            data.Clear();

            var members = target.GetSerializedMembers();

            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);
                }
            }
        }