Guest User

Untitled

a guest
Dec 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public class RxSample : MonoBehaviour
  2. {
  3. class SampleResponse
  4. {
  5. public int value1;
  6. public int value2;
  7. }
  8.  
  9. class SampleData
  10. {
  11. public readonly IntReactiveProperty Value1 = new IntReactiveProperty();
  12. public readonly IntReactiveProperty Value2 = new IntReactiveProperty();
  13.  
  14. public SampleData(SampleResponse response)
  15. {
  16. UpdateData(response);
  17. }
  18.  
  19. public void UpdateData(SampleResponse response)
  20. {
  21. Value1.Value = response.value1;
  22. Value2.Value = response.value2;
  23. }
  24. }
  25.  
  26. [SerializeField] Text Value1Text;
  27. [SerializeField] Text Value2Text;
  28. [SerializeField] Button ReloadButton;
  29.  
  30. SampleData _sample;
  31.  
  32. void Start()
  33. {
  34. if (_sample == null)
  35. {
  36. _sample = new SampleData(new SampleResponse() {value1 = 10, value2 = 20});
  37. }
  38.  
  39. _sample.Value1.SubscribeToText(Value1Text).AddTo(this);
  40. _sample.Value2.SubscribeToText(Value2Text).AddTo(this);
  41.  
  42. //データ更新があったら
  43. ReloadButton.OnClickAsObservable()
  44. .Subscribe(_ => _sample.UpdateData(new SampleResponse() {value1 = 1000, value2 = 2000}))
  45. .AddTo(this);
  46. }
  47. }
Add Comment
Please, Sign In to add comment