【Unity】【UniRx】ReactiveProperty で値を監視する

using UnityEngine;
using UniRx;

public class Sample : MonoBehaviour
{
    private ReactiveProperty<int> _intValue = new ReactiveProperty<int>();
    
    private void Start()
    {
        // 変数を購読する
        this._intValue
            .Subscribe(value =>
            {
                Debug.Log($"[Subscribe]value={value}");
            });
        // 値を更新する
        this._intValue.Value = 1;
    }
}

ReactiveProperty<T> 以外にも下記のようなクラスがある。

  • IntReactiveProperty
  • LongReactiveProperty
  • ByteReactiveProperty
  • FloatReactiveProperty
  • DoubleReactiveProperty
  • StringReactiveProperty
  • BoolReactiveProperty
  • Vector2ReactiveProperty
  • Vector3ReactiveProperty
  • Vector4ReactiveProperty
  • ColorReactiveProperty
  • RectReactiveProperty
  • AnimationCurveReactiveProperty
  • BoundsReactiveProperty
  • QuaternionReactiveProperty