Created
May 13, 2017 03:32
-
-
Save su10/896f8635c2f2ed9835a9a7181d5d2c5d to your computer and use it in GitHub Desktop.
【Unity】PhotonNetwork.OnEventCallをAsObservableにする【PhotonRx】 ref: http://qiita.com/su10/items/1b7a792ce9bd90debdb0
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
// 使い方 | |
PhotonNetwork.OnEventCall | |
.AsObservable() | |
.Subscribe(tuple => | |
{ | |
var eventCode = tuple.Item1; | |
var content = tuple.Item2; | |
var senderId = tuple.Item3; | |
Debug.Log("OnEventCall"); | |
}); |
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
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