Hi,
I am trying to use ScriptableObjects as databases by storing lists of indexed values.
As dictionary are not natively serializable I tried using lists like so
[System.Serializable]
public class TableEntry<T>
{
public string key;
public T value;
}
public abstract class DataTable<T> : ScriptableObject
{
public List<TableEntry<T>> entries;
}
[CreateAssetMenu(menuName = "ObjectTable")]
public class ObjectTable : DataTable<object>
{
public string GetKey(object value)
{
for (int i = 0, j = entries.Count; i < j; i++)
{
if (entries*.value == value)*
{
return entries*.key;*
}
}
return null;
}
public object GetValue(string key)
{
for (int i = 0, j = entries.Count; i < j; i++)
{
if (entries*.key == key)*
{
return entries*.value;*
}
}
return null;
}
}
But whatever I do Unity seems to refuse serializing containers of generic types.
I tried different solutions but I always end up breaking the genericity or with no serialization at all.
Is there a known workaround for this ?
Thanks