「Unity/UniRx/Subject」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
ページの作成:「==サンプル== <pre> Subject<string> subject = new Subject<string>(); // イベント登録 subject.Subscribe(msg => Debug.Log("msg1:" + msg)); subject.Subscribe(msg =...」
 
5行目: 5行目:
// イベント登録
// イベント登録
subject.Subscribe(msg => Debug.Log("msg1:" + msg));
subject.Subscribe(msg => Debug.Log("msg1:" + msg));
subject.Subscribe(msg => Debug.Log("msg2:" + msg));


// イベント発行
// イベント発行
subject.OnNext("hello");
subject.OnNext("hello");
subject.OnNext("world");
</pre>
</pre>
ログ
ログ
<pre>
<pre>
msg1:hello
msg1:hello
msg2:hello
msg1:world
msg2:world
</pre>
</pre>


参考:https://qiita.com/toRisouP/items/2f1643e344c741dd94f8
参考:https://qiita.com/toRisouP/items/2f1643e344c741dd94f8

2021年10月13日 (水) 16:35時点における版

サンプル

Subject<string> subject = new Subject<string>();

// イベント登録
subject.Subscribe(msg => Debug.Log("msg1:" + msg));

// イベント発行
subject.OnNext("hello");

ログ

msg1:hello

参考:https://qiita.com/toRisouP/items/2f1643e344c741dd94f8