R3Test.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #if LITMOTION_TEST_R3
  2. using System;
  3. using System.Collections;
  4. using UnityEngine;
  5. using UnityEngine.TestTools;
  6. using R3;
  7. using NUnit.Framework;
  8. namespace LitMotion.Tests.Runtime
  9. {
  10. public class R3Test
  11. {
  12. readonly CompositeDisposable disposables = new();
  13. [OneTimeTearDown]
  14. public void OneTimeTearDown()
  15. {
  16. disposables.Dispose();
  17. }
  18. [UnityTest]
  19. public IEnumerator Test_ToObservable()
  20. {
  21. bool completed = false;
  22. LMotion.Create(0f, 10f, 2f)
  23. .WithOnComplete(() => completed = true)
  24. .ToR3Observable()
  25. .Subscribe(x => Debug.Log(x))
  26. .AddTo(disposables);
  27. while (!completed) yield return null;
  28. }
  29. [UnityTest]
  30. public IEnumerator Test_BindToReactiveProperty()
  31. {
  32. var reactiveProperty = new ReactiveProperty<float>();
  33. reactiveProperty.AddTo(disposables);
  34. bool completed = false;
  35. LMotion.Create(0f, 10f, 2f)
  36. .WithOnComplete(() => completed = true)
  37. .BindToReactiveProperty(reactiveProperty)
  38. .ToDisposable()
  39. .AddTo(disposables);
  40. reactiveProperty.Subscribe(x =>
  41. {
  42. Debug.Log(x);
  43. })
  44. .AddTo(disposables);
  45. while (!completed) yield return null;
  46. }
  47. }
  48. }
  49. #endif