回答編集履歴

1

Subscribeを初期化時のみに行うパターンを追記

2022/03/26 21:23

投稿

Bongo
Bongo

スコア10807

test CHANGED
@@ -55,3 +55,33 @@
55
55
  }
56
56
  }
57
57
  ```
58
+
59
+ あるいは`Subscribe`は初期化時のみに行うというルールに準拠するとなると、`WaveManager`は下記のようにすることになるでしょうかね?
60
+
61
+ ```C#
62
+ using UniRx;
63
+ using UnityEngine;
64
+
65
+ public class WaveManager : MonoBehaviour
66
+ {
67
+ [SerializeField] private MainView mainView;
68
+ [SerializeField] private TimeSet timeSet;
69
+
70
+ private readonly ISubject<Unit> _onWeaponBarHideRequested = new Subject<Unit>();
71
+
72
+ private void Awake()
73
+ {
74
+ _onWeaponBarHideRequested.SelectMany(
75
+ timeSet.ReserveCountTime
76
+ .Do(x => Debug.Log($"Timer count: {x}"))
77
+ .DoOnCompleted(() => mainView.WeaponBarHide()))
78
+ .Subscribe().AddTo(this);
79
+ }
80
+
81
+ public void ReserveCountTimeStart()
82
+ {
83
+ Debug.Log("CountStart");
84
+ _onWeaponBarHideRequested.OnNext(Unit.Default);
85
+ }
86
+ }
87
+ ```