Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RxSample : MonoBehaviour
- {
- class SampleResponse
- {
- public int value1;
- public int value2;
- }
- class SampleData
- {
- public readonly IntReactiveProperty Value1 = new IntReactiveProperty();
- public readonly IntReactiveProperty Value2 = new IntReactiveProperty();
- public SampleData(SampleResponse response)
- {
- UpdateData(response);
- }
- public void UpdateData(SampleResponse response)
- {
- Value1.Value = response.value1;
- Value2.Value = response.value2;
- }
- }
- [SerializeField] Text Value1Text;
- [SerializeField] Text Value2Text;
- [SerializeField] Button ReloadButton;
- SampleData _sample;
- void Start()
- {
- if (_sample == null)
- {
- _sample = new SampleData(new SampleResponse() {value1 = 10, value2 = 20});
- }
- _sample.Value1.SubscribeToText(Value1Text).AddTo(this);
- _sample.Value2.SubscribeToText(Value2Text).AddTo(this);
- //データ更新があったら
- ReloadButton.OnClickAsObservable()
- .Subscribe(_ => _sample.UpdateData(new SampleResponse() {value1 = 1000, value2 = 2000}))
- .AddTo(this);
- }
- }
Add Comment
Please, Sign In to add comment