using System; using System.Collections.Generic; using UnityEngine; using UnityAtoms.Extensions; namespace UnityAtoms { public abstract class ScriptableObjectList : ScriptableObject where E : GameEvent { public E Added; public E Removed; public VoidEvent Cleared; public int Count { get { return list.Count; } } [SerializeField] private List list = new List(); public void Add(T item) { if (!list.Contains(item)) { list.Add(item); if (null != Added) { Added.Raise(item); } } } public void Remove(T item) { if (list.Contains(item)) { list.Remove(item); if (null != Removed) { Removed.Raise(item); } } } public void Clear() { list.Clear(); if (null != Cleared) { Cleared.Raise(); } } public bool Some(Func func) { return list.Some(func); } public T First(Func func) { return list.First(func); } public bool Contains(T item) { return list.Contains(item); } public T Get(int i) { return list[i]; } public List List { get { return list; } set { list = value; } } public T this[int index] { get { return list[index]; } set { list[index] = value; } } } }