idle-survivors/Assets/Scripts/RuntimeSet/RuntimeSetSO.cs
Michael ad725ee518
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
refactor: unify runtime sets, update naming of event channels (#17)
Some general refactors:
Turns HeroPartySO into a runtime set class.
Make runtime set an IEnumerable
Simplify name of events

Reviewed-on: #17
Reviewed-by: zephyr <zephyr@noreply.localhost>
Co-authored-by: Michael <mep053@gmail.com>
Co-committed-by: Michael <mep053@gmail.com>
2023-08-12 22:26:36 -05:00

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();
}
}
}