41 lines
952 B
C#
41 lines
952 B
C#
|
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();
|
||
|
}
|
||
|
}
|
||
|
}
|