Last active
July 6, 2017 14:40
-
-
Save su10/0ad69cc37789aa7c9784ac16f2f69ee2 to your computer and use it in GitHub Desktop.
【Unity】Subscribeしなくても動作してかつSubscribeすることで結果も必ず受け取れるストリームを作る方法【UniRx】 ref: http://qiita.com/su10/items/caffe7877adfab54263c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using UniRx; | |
public class WaitForObservable : MonoBehaviour | |
{ | |
[SerializeField] | |
private Window _window; | |
void Start() | |
{ | |
var showStream = _window.Show(); | |
// WARNING: Subscribe前にShowStreamが完了しているのでDebug.Logは呼ばれない! | |
Observable.Timer(TimeSpan.FromSeconds(1.5f)).Subscribe(_ => { | |
showStream.Subscribe(__ => Debug.Log("OnNext()")); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IObservable<Unit> Show() | |
{ | |
return Observable.FromCoroutine(ShowCoroutine).Replay().RefCount(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment