You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
987 B
C#
39 lines
987 B
C#
3 weeks ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Unity.BossRoom.Infrastructure
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// ScriptableObject class that contains a list of a given type. The instance of this ScriptableObject can be
|
||
|
/// referenced by components, without a hard reference between systems.
|
||
|
/// </summary>
|
||
|
/// <typeparam name="T"></typeparam>
|
||
|
public abstract class RuntimeCollection<T> : ScriptableObject
|
||
|
{
|
||
|
public List<T> Items = new List<T>();
|
||
|
|
||
|
public event Action<T> ItemAdded;
|
||
|
|
||
|
public event Action<T> ItemRemoved;
|
||
|
|
||
|
public void Add(T item)
|
||
|
{
|
||
|
if (!Items.Contains(item))
|
||
|
{
|
||
|
Items.Add(item);
|
||
|
ItemAdded?.Invoke(item);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void Remove(T item)
|
||
|
{
|
||
|
if (Items.Contains(item))
|
||
|
{
|
||
|
Items.Remove(item);
|
||
|
ItemRemoved?.Invoke(item);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|