There is data structure:
[Serializable]
public sealed class UnisonProjectData : ScriptableObject
{
[SerializeField] private IntUnisonBaseTypeMetaDictionary _unisonBaseTypeMetaById = new IntUnisonBaseTypeMetaDictionary();
. . .
}
[Serializable]
public sealed class UnisonBaseTypeMeta : UnisonTypeMeta
{
public IntUnisonImplementationTypeMetaDictionary ImplementationsById;
public string ResourcesRootPath;
. . .
}
[Serializable]
public sealed class UnisonImplementationTypeMeta : UnisonTypeMeta
{
. . .
}
[Serializable]
public /*abstract*/ class UnisonTypeMeta
{
public int Id;
public string Name;
}
[Serializable]
public class IntUnisonBaseTypeMetaDictionary : SerializableDictionary<int, UnisonBaseTypeMeta>
{
}
[Serializable]
public class IntUnisonImplementationTypeMetaDictionary : SerializableDictionary<int, UnisonImplementationTypeMeta>
{
}
[Serializable]
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
{
[SerializeField]
private List<TKey> keys;
[SerializeField]
private List<TValue> values;
public SerializableDictionary()
{
keys = new List<TKey>();
values = new List<TValue>();
}
public SerializableDictionary(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
// save the dictionary to lists
public void OnBeforeSerialize()
{
keys.Clear();
values.Clear();
foreach (KeyValuePair<TKey, TValue> pair in this)
{
keys.Add(pair.Key);
values.Add(pair.Value);
}
}
// load dictionary from lists
public void OnAfterDeserialize()
{
this.Clear();
if (keys.Count != values.Count)
throw new System.Exception(string.Format("there are {0} keys and {1} values after deserialization. Make sure that both key and value types are serializable."));
for (int i = 0; i < keys.Count; i++)
this.Add(keys_, values*);*_
}
}
UnisonProjectData is a singletone ScriptableObject that is saved as an asset to a specific location. It is being populated with generated data on DidReloadScripts event. This data is generated using reflection.
Everything works great inside the editor and in the playmode. But sometimes when I restart the editor all the data is gone and sometimes it is there.
Here is the content of the asset file (with Force Text Serialization option).
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
— !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7afc552a07e5ad34fb2b6a3405ec2ffd, type: 3}
m_Name: UnisonProjectData
m_EditorClassIdentifier:
_unisonBaseTypeMetaById:
keys:
values: []
What is interesting when i opened Unity last time the data was there, but the file didn’t had that information.
I am probably missing something.