Skip to content

Instantly share code, notes, and snippets.

@su10
Last active July 6, 2017 14:40
Show Gist options
  • Save su10/0ad69cc37789aa7c9784ac16f2f69ee2 to your computer and use it in GitHub Desktop.
Save su10/0ad69cc37789aa7c9784ac16f2f69ee2 to your computer and use it in GitHub Desktop.
【Unity】Subscribeしなくても動作してかつSubscribeすることで結果も必ず受け取れるストリームを作る方法【UniRx】 ref: http://qiita.com/su10/items/caffe7877adfab54263c
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()"));
});
}
}
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