-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuxServicedController.cs
More file actions
56 lines (49 loc) · 1.77 KB
/
AuxServicedController.cs
File metadata and controls
56 lines (49 loc) · 1.77 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;
using UnityEngine;
using Cysharp.Threading.Tasks;
using VContainer.Unity;
using MessagePipe;
namespace MyGame
{
// Для тестирования ITickable и шины с топиками.
public class AuxServicedController : ITickable, IStartable, IDisposable
{
readonly HelloWorldService helloWorldService;
readonly IPublisher<int> publisher;
readonly ISubscriber<AnimationSwitchEventSubscriber, AnimationSwitchEvent> subscriber;
IDisposable disposable;
public AuxServicedController(HelloWorldService helloWorldService, IPublisher<int> publisher, ISubscriber<AnimationSwitchEventSubscriber, AnimationSwitchEvent> subscriber)
{
this.helloWorldService = helloWorldService;
this.publisher = publisher;
this.subscriber = subscriber;
}
void OnAnimationSwitchEvent(AnimationSwitchEvent e)
{
if (e.isOn)
{
publisher.Publish(0x0A1);
}
else
{
publisher.Publish(0x0FF);
}
}
void IStartable.Start()
{
var d = DisposableBag.CreateBuilder();
// Подписываемся на шину с топиком, равному AnimationSwitchEventSubscriber.Second
subscriber.Subscribe(AnimationSwitchEventSubscriber.Second, OnAnimationSwitchEvent).AddTo(d);
disposable = d.Build();
}
void IDisposable.Dispose()
{
disposable.Dispose();
Debug.Log("AuxServicedController Disposed!");
}
void ITickable.Tick()
{
helloWorldService.Noop();
}
}
}