LoginSignup
0
3

More than 3 years have passed since last update.

UniRx 書き方サンプルメモ

Last updated at Posted at 2017-05-04

ReactiveStringの変化購読

ReactiveString.Where(value => value == Co.MODE_STOP).Subscribe( value => {
//stringが変更された時の処理
});

ReactiveCollectionの初期化

ReactiveCollection<bool> reactiveCollection = new ReactiveCollection<bool>(){true,false,false,false};

ReactiveCollectionのネスト

宣言
private ReactiveCollection<bool> collection;
public ReactiveCollection<ReactiveCollection<bool>> collections;
初期化
collection = new ReactiveCollection<bool>(){true,false,false,false,true,false,false,false,true,false,false,false,true,false,false,true};
collections = new ReactiveCollection<ReactiveCollection<bool>>(){Sequence};

KeyEventのReactive化

Stream
IObservable<bool>  keydownStream = this.UpdateAsObservable().ObserveEveryValueChanged(_ => Input.GetKeyDown(keycode)).Where(x => x);
Subscribe
keydownStream.Subscribe(_ => Debug.Log("KeyDown"));

購読の停止

.Subscribe の戻り値がIDisposable .Dispose();で購読停止可能。

ReactiveEnum を自分で定義して State 管理

State
public class StateManager : MonoBehaviour
{
    public StateReactiveProperty appState = new StateReactiveProperty(APP_STATE.WAITING);

    public enum APP_STATE
    {
        WAITING = 0,
        PLAY,
        COUNT_DOWN,
        FINISH
    }

    // Start is called before the first frame update
    void Start()
    {
       appState.Subscribe(value =>
       {
           Debug.Log("APP_STATE:" + value);
       });
    }
}

[System.Serializable]
public class StateReactiveProperty : ReactiveProperty<StateManager.APP_STATE>
{
    public StateReactiveProperty() { }
    public StateReactiveProperty(StateManager.APP_STATE initialValue) : base(initialValue) { }
}

追記していきます。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3