-
Notifications
You must be signed in to change notification settings - Fork 1
/
GroupUniRxExtendedAdditions.cs
executable file
·51 lines (41 loc) · 2.25 KB
/
GroupUniRxExtendedAdditions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using UniRx;
namespace Entitas {
public class AnyEntityChangeEventArgs<T> : EventArgs {
public GroupChangedEventArgs<T> addition;
public GroupUpdatedEventArgs<T> update;
public GroupChangedEventArgs<T> removal;
}
public partial class Group {
/** A component of type T had any of the changes specified in 'changeTypes' within the group. The appropriate 'update', 'addition' or 'removal' field will be set in the resulting AnyEntityChangeEventArgs. */
public IObservable<AnyEntityChangeEventArgs<T>> OnAnyEntityChangeObservable<T>(ChangeType changeTypes = ChangeType.Addition | ChangeType.Replacement | ChangeType.Removal){
List<IObservable<AnyEntityChangeEventArgs<T>>> observedChanges = new List<IObservable<AnyEntityChangeEventArgs<T>>>();
if((changeTypes & ChangeType.Addition) == ChangeType.Addition){
var entityAdded = OnEntityAddedAsObservable<T>().Select<GroupChangedEventArgs<T>, AnyEntityChangeEventArgs<T>>(addition => {
var change = new AnyEntityChangeEventArgs<T>();
change.addition = addition;
return change;
});
observedChanges.Add(entityAdded);
}
if((changeTypes & ChangeType.Replacement) == ChangeType.Replacement){
var entityUpdated = OnEntityUpdatedAsObservable<T>().Select<GroupUpdatedEventArgs<T>, AnyEntityChangeEventArgs<T>>(update => {
var change = new AnyEntityChangeEventArgs<T>();
change.update = update;
return change;
});
observedChanges.Add(entityUpdated);
}
if((changeTypes & ChangeType.Removal) == ChangeType.Removal){
var entityRemoved = OnEntityRemovedAsObservable<T>().Select<GroupChangedEventArgs<T>, AnyEntityChangeEventArgs<T>>(removal => {
var change = new AnyEntityChangeEventArgs<T>();
change.removal = removal;
return change;
});
observedChanges.Add(entityRemoved);
}
return Observable.Merge(observedChanges);
}
}
}