using Rokoko.Core;
using System.Collections;
using System.Collections.Generic;
///
/// Create a simple serialized version of a Dictionary in order to able to persist in Editor play mode.
///
[System.Serializable]
public abstract class SerializableDictionary
{
public List keys = new List();
public List values = new List();
public void Add(TKey key, TValue value)
{
if (keys.Contains(key))
throw new System.Exception("Key already exists");
keys.Add(key);
values.Add(value);
}
public TValue this[TKey key]
{
get
{
if (!keys.Contains(key))
throw new System.Exception("Key doesn't exists");
return values[keys.IndexOf(key)];
}
set
{
if (!keys.Contains(key))
throw new System.Exception("Key doesn't exists");
int index = keys.IndexOf(key);
values[index] = value;
}
}
public KeyValuePair this[int index]
{
get
{
if (keys.Count < index)
throw new System.IndexOutOfRangeException();
return new KeyValuePair(keys[index], values[index]);
}
}
public bool Contains(TKey key)
{
return keys.Contains(key);
}
public void Clear()
{
keys.Clear();
values.Clear();
}
public int Count => keys.Count;
}