-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSystemServiceMonoBehavior.cs
More file actions
56 lines (50 loc) · 1.72 KB
/
SystemServiceMonoBehavior.cs
File metadata and controls
56 lines (50 loc) · 1.72 KB
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
52
53
54
55
56
using System.Collections;
using UniRx;
namespace uFrame.Kernel
{
/// <summary>
/// The base class for all services on the kernel. Services provide an easy communication layer with the use
/// of the EventAggregator. You can use this.Publish(new AnyType()). Or you can use this.OnEvent<AnyType>().Subscribe(anyTypeInstance=>{ });
/// In services you can also inject any instances that are setup in any of the SystemLoaders.
/// </summary>
public abstract class SystemServiceMonoBehavior : uFrameComponent, ISystemService, IDisposableContainer
{
private CompositeDisposable _disposer = new CompositeDisposable();
public CompositeDisposable Disposer
{
get { return _disposer; }
set { _disposer = value; }
}
IEventAggregator ISystemService.EventAggregator
{
get { return EventAggregator; }
set
{
// No need to set
}
}
/// <summary>
/// This method is to setup an listeners on the EventAggregator, or other initialization requirements.
/// </summary>
public virtual void Setup()
{
if (Disposer.IsDisposed)
{
Disposer = new CompositeDisposable();
}
}
/// <summary>
/// This method is called by the kernel to do any setup the make take some time to complete. It is executed as
/// a co-routine by the kernel.
/// </summary>
/// <returns></returns>
public virtual IEnumerator SetupAsync()
{
yield break;
}
protected override void OnDestroy()
{
Disposer.Dispose();
}
}
}