Skip to content

Commit ee1db49

Browse files
author
Cory Leach
committedAug 25, 2022
Update RuntimeSet.cs
1 parent cb4ea98 commit ee1db49

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed
 

‎Runtime/RuntimeSets/RuntimeSet.cs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using UnityEngine;
3+
using UnityEngine.Events;
44

55
namespace Gameframe.ScriptableObjects.RuntimeSets
66
{
77
public class RuntimeSet<T> : ScriptableObject
88
{
9+
public class RuntimeSetChangeEvent : UnityEvent<T> {}
910

10-
List<T> items = new List<T>();
11-
public List<T> Items => items;
11+
private readonly List<T> _items = new List<T>();
12+
public IReadOnlyList<T> Items => _items;
13+
14+
public RuntimeSetChangeEvent OnAdded { get; } = new RuntimeSetChangeEvent();
15+
public RuntimeSetChangeEvent OnRemoved { get; } = new RuntimeSetChangeEvent();
1216

1317
public void Add(T t)
1418
{
15-
items.Add(t);
19+
_items.Add(t);
20+
OnAdded.Invoke(t);
1621
}
1722

1823
public void Remove(T t)
1924
{
20-
items.Remove(t);
25+
_items.Remove(t);
26+
OnRemoved.Invoke(t);
2127
}
22-
2328
}
24-
}
29+
}

0 commit comments

Comments
 (0)
Failed to load comments.