C# Everywhere Windows Desktop WinForms, WPF Windows 8 Windows Universal apps Mac application Xamarin.Mac Web application ASP .NET MVC, ASP .NET Web API Game Unity, Paradox, Unreal Engine Mobile (iOS, Android, WP) MonoTouch, Mono for Android Embedded, IoT .NET Framework Embedded Cloud Windows Azure, AWS
Reactive Extensions (Rx) LINQ to Events LINQ が扱うデータ ソースの概念を「イベント」に広げる LINQ to Objects • Array • List • Stream • etc… LINQ to XML • XML • JSON LINQ to Events • User (input) • Sensor device (input) • Web service (notification) • etc... あらゆるものがイベント
Simple Calculation ストリームの結合 public class CalculatorPresenter : MonoBehaviour { public InputField Left; public InputField Right; public Text Result; void Start() { var left = this.Left .OnValueChangeAsObservable() .Select(x => int.Parse(x)); var right = this.Right .OnValueChangeAsObservable() .Select(x => int.Parse(x)); left.CombineLatest(right, (l, r) => l + r) .SubscribeToText(this.Result); } }
Simple Calculation ストリームの結合 public class CalculatorPresenter : MonoBehaviour { public InputField Left; public InputField Right; public Text Result; void Start() { var left = this.Left .OnValueChangeAsObservable() .Select(x => int.Parse(x)); var right = this.Right .OnValueChangeAsObservable() .Select(x => int.Parse(x)); left.CombineLatest(right, (l, r) => l + r) .SubscribeToText(this.Result); } } OnValueChangeAsObservable() で UniRx のイベント ストリーム (IObseravable) にする
Count up / down UniRx (+ Reactive Property) を使って MV(R)P // Presenter public class UpDownPresenter : MonoBehaviour { // View public Button UpButton; public Button DownButton; public Text ScoreText; // Model [InspectorDisplay] public IntReactiveProperty Score; private void Start() { this.UpButton.OnClickAsObservable().Subscribe(_ => this.Score.Value++); this.DownButton.OnClickAsObservable().Subscribe(_ => this.Score.Value--); this.Score.SubscribeToText(this.ScoreText); } } Passive View Presenter (Supervising Controller) Model updates view state-change events user events update model
Count up / down UniRx (+ Reactive Property) を使って MV(R)P // Presenter public class UpDownPresenter : MonoBehaviour { // View public Button UpButton; public Button DownButton; public Text ScoreText; // Model [InspectorDisplay] public IntReactiveProperty Score; private void Start() { this.UpButton.OnClickAsObservable().Subscribe(_ => this.Score.Value++); this.DownButton.OnClickAsObservable().Subscribe(_ => this.Score.Value--); this.Score.SubscribeToText(this.ScoreText); } } Passive View Presenter (Supervising Controller) Model updates view state-change events user events update model user events を受信した Presenter が Model (Score) を update
Count up / down UniRx (+ Reactive Property) を使って MV(R)P // Presenter public class UpDownPresenter : MonoBehaviour { // View public Button UpButton; public Button DownButton; public Text ScoreText; // Model [InspectorDisplay] public IntReactiveProperty Score; private void Start() { this.UpButton.OnClickAsObservable().Subscribe(_ => this.Score.Value++); this.DownButton.OnClickAsObservable().Subscribe(_ => this.Score.Value--); this.Score.SubscribeToText(this.ScoreText); } } Passive View Presenter (Supervising Controller) Model updates view state-change events user events update model Model が state-change event を配信 (ReactiveProperty のイベント ストリーム)