This list is not showing on the inspector and afaik inspector supports polymorphism. So I don’t understand why it s not shown in the inspector.
[Serializable]
public class ObservedList<T> : List<T>
{
public event Action<int> Changed = delegate { };
public event Action<T> Added = delegate { };
public event Action<T> Removed = delegate { };
public event Action Updated = delegate { };
public new void Add(T item)
{
base.Add(item);
Added(item);
Updated();
}
public new void Remove(T item)
{
Removed(item);
base.Remove(item);
Updated();
}
public new void AddRange(IEnumerable<T> collection)
{
base.AddRange(collection);
foreach (var item in collection)
Added(item);
Updated();
}
public new void RemoveRange(int index, int count)
{
for (int i = index; i < count; i++)
Remove(this[index]);
base.RemoveRange(index, count);
Updated();
}
public new void Clear()
{
foreach(var item in this)
Remove(item);
base.Clear();
Updated();
}
public new void Insert(int index, T item)
{
base.Insert(index, item);
Added(item);
Updated();
}
public new void InsertRange(int index, IEnumerable<T> collection)
{
base.InsertRange(index, collection);
foreach (var item in collection)
Added(item);
Updated();
}
public new void RemoveAll(Predicate<T> match)
{
base.RemoveAll(match);
Updated();
}
public new T this[int index]
{
get { return base[index]; }
set
{
base[index] = value;
Changed(index);
}
}
}
public ObservedList<string> Test;