ObservableAnimatorTrigger.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System; // require keep for Windows Universal App
  2. using UnityEngine;
  3. namespace UniRx.Triggers
  4. {
  5. [DisallowMultipleComponent]
  6. public class ObservableAnimatorTrigger : ObservableTriggerBase
  7. {
  8. Subject<int> onAnimatorIK;
  9. /// <summary>Callback for setting up animation IK (inverse kinematics).</summary>
  10. void OnAnimatorIK(int layerIndex)
  11. {
  12. if (onAnimatorIK != null) onAnimatorIK.OnNext(layerIndex);
  13. }
  14. /// <summary>Callback for setting up animation IK (inverse kinematics).</summary>
  15. public IObservable<int> OnAnimatorIKAsObservable()
  16. {
  17. return onAnimatorIK ?? (onAnimatorIK = new Subject<int>());
  18. }
  19. Subject<Unit> onAnimatorMove;
  20. /// <summary>Callback for processing animation movements for modifying root motion.</summary>
  21. void OnAnimatorMove()
  22. {
  23. if (onAnimatorMove != null) onAnimatorMove.OnNext(Unit.Default);
  24. }
  25. /// <summary>Callback for processing animation movements for modifying root motion.</summary>
  26. public IObservable<Unit> OnAnimatorMoveAsObservable()
  27. {
  28. return onAnimatorMove ?? (onAnimatorMove = new Subject<Unit>());
  29. }
  30. protected override void RaiseOnCompletedOnDestroy()
  31. {
  32. if (onAnimatorIK != null)
  33. {
  34. onAnimatorIK.OnCompleted();
  35. }
  36. if (onAnimatorMove != null)
  37. {
  38. onAnimatorMove.OnCompleted();
  39. }
  40. }
  41. }
  42. }