1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 1
- using System . Collections ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Generic ;
3
2
using UnityEngine ;
3
+ using UnityEngine . Events ;
4
4
5
5
namespace Gameframe . ScriptableObjects . RuntimeSets
6
6
{
7
7
public class RuntimeSet < T > : ScriptableObject
8
8
{
9
+ public class RuntimeSetChangeEvent : UnityEvent < T > { }
9
10
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 ( ) ;
12
16
13
17
public void Add ( T t )
14
18
{
15
- items . Add ( t ) ;
19
+ _items . Add ( t ) ;
20
+ OnAdded . Invoke ( t ) ;
16
21
}
17
22
18
23
public void Remove ( T t )
19
24
{
20
- items . Remove ( t ) ;
25
+ _items . Remove ( t ) ;
26
+ OnRemoved . Invoke ( t ) ;
21
27
}
22
-
23
28
}
24
- }
29
+ }
0 commit comments