Posted at

TouchScriptのジェスチャーイベントをObservableに変換する拡張メソッド

More than 1 year has passed since last update.


public static IObservable<Unit> TapAsObservable(this TapGesture gesture)
{
return Observable.FromEventPattern<EventHandler<EventArgs>, EventArgs>(
h => h.Invoke,
h => gesture.Tapped += h,
h => gesture.Tapped -= h)
.AsUnitObservable();
}

こゆこと

参考

https://github.com/neuecc/UniRx/blob/master/Assets/Plugins/UniRx/Examples/Sample09_EventHandling.cs