Skip to content

Instantly share code, notes, and snippets.

@su10
Created May 13, 2017 03:32
Show Gist options
  • Save su10/896f8635c2f2ed9835a9a7181d5d2c5d to your computer and use it in GitHub Desktop.
Save su10/896f8635c2f2ed9835a9a7181d5d2c5d to your computer and use it in GitHub Desktop.
【Unity】PhotonNetwork.OnEventCallをAsObservableにする【PhotonRx】 ref: http://qiita.com/su10/items/1b7a792ce9bd90debdb0
// 使い方
PhotonNetwork.OnEventCall
.AsObservable()
.Subscribe(tuple =>
{
var eventCode = tuple.Item1;
var content = tuple.Item2;
var senderId = tuple.Item3;
Debug.Log("OnEventCall");
});
namespace UniRx
{
public static class PhotonExtensions
{
public static IObservable<Tuple<byte, object, int>> AsObservable(this PhotonNetwork.EventCallback eventCallback)
{
return Observable.FromEvent<PhotonNetwork.EventCallback, Tuple<byte, object, int>>(
h => (x, y, z) => h(Tuple.Create(x, y, z)),
h => PhotonNetwork.OnEventCall += h,
h => PhotonNetwork.OnEventCall -= h
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment