2023-08-12 23:26:36 -04:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace RuntimeSet
|
|
|
|
{
|
|
|
|
public abstract class RuntimeSetSO<T> : ScriptableObject, IEnumerable<T>
|
|
|
|
{
|
|
|
|
[HideInInspector] [SerializeField] private List<T> items = new();
|
|
|
|
|
|
|
|
protected IReadOnlyCollection<T> Items => items;
|
|
|
|
public bool IsEmpty => items.Count == 0;
|
|
|
|
public int Count => items.Count;
|
|
|
|
|
|
|
|
public void Add(T item)
|
|
|
|
{
|
|
|
|
if (!items.Contains(item))
|
|
|
|
{
|
|
|
|
items.Add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove(T item)
|
|
|
|
{
|
|
|
|
if (items.Contains(item))
|
|
|
|
{
|
|
|
|
items.Remove(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
|
|
{
|
|
|
|
return items.GetEnumerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
{
|
|
|
|
return GetEnumerator();
|
|
|
|
}
|
2023-08-16 22:54:48 -04:00
|
|
|
|
|
|
|
public T this[int index] { get { return items[index]; } }
|
2023-08-12 23:26:36 -04:00
|
|
|
}
|
|
|
|
}
|