internal string SerializePreferences() { if (m_Preferences == null) { m_Preferences = new SerializedPreferences(); } var serializerTypes = new HashSet <Type>(); foreach (var serializer in m_Serializers) { var payload = serializer.OnSerializePreferences(); if (payload == null) { continue; } var type = serializer.GetType(); if (!serializerTypes.Add(type)) { Debug.LogWarning(string.Format("Multiple payloads of type {0} on serialization", type)); } m_Preferences.items[type] = new SerializedPreferenceItem { name = type.FullName, payloadType = payload.GetType().FullName, payload = JsonUtility.ToJson(payload) }; } return(JsonUtility.ToJson(m_Preferences)); }
internal string SerializePreferences() { var preferences = new SerializedPreferences(); foreach (var serializer in m_Serializers) { var payload = serializer.OnSerializePreferences(); SerializedPreferenceItem item = null; if (payload == null) { if (m_Preferences != null) { // Use the previously saved preferences for this serializer item = m_Preferences.items.SingleOrDefault(pi => pi.name == serializer.GetType().FullName); } } else { item = new SerializedPreferenceItem(); item.name = serializer.GetType().FullName; item.payloadType = payload.GetType().FullName; item.payload = JsonUtility.ToJson(payload); } if (item != null) { preferences.items.Add(item); } } m_Preferences = preferences; return(JsonUtility.ToJson(preferences)); }
internal void DeserializePreferences(string serializedPreferences) { var preferences = JsonUtility.FromJson <SerializedPreferences>(serializedPreferences); if (preferences != null) { m_Preferences = preferences; foreach (var serializer in m_Serializers) { Deserialize(serializer); } } }
static void Deserialize(SerializedPreferences preferences, ISerializePreferences serializer) { SerializedPreferenceItem item; if (preferences.items.TryGetValue(serializer.GetType(), out item)) { var type = Type.GetType(item.payloadType); if (type == null) { return; } var payload = JsonUtility.FromJson(item.payload, type); serializer.OnDeserializePreferences(payload); } }
internal void DeserializePreferences(string serializedPreferences) { var preferences = JsonUtility.FromJson <SerializedPreferences>(serializedPreferences); if (preferences != null) { m_Preferences = preferences; foreach (var serializer in m_Serializers) { var item = preferences.items.SingleOrDefault(pi => pi.name == serializer.GetType().FullName); if (item != null) { var payload = JsonUtility.FromJson(item.payload, Type.GetType(item.payloadType)); serializer.OnDeserializePreferences(payload); } } } }
internal void SetupWithPreferences(string serializedPreferences) { m_Preferences = DeserializePreferences(serializedPreferences, m_Serializers); }
public void Initialize() { Preferences = SerializedPreferences.Deserialize(serializedPreferences); }