CustomTweener.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using UnityEngine;
  3. namespace Utility.CTween
  4. {
  5. public class CustomTweener
  6. {
  7. public AnimationCurve AnimationCurve = CustomTweenManager.AnimationCurveLibrary.Line;
  8. public Action OnCompleteAction;
  9. public Action OnUpdateAction;
  10. public Action<object> OnUpdateAndValueAction;
  11. public Action OnDestroyAction;
  12. public float Duration;
  13. protected bool _isKilled;
  14. protected bool _isPause;
  15. protected bool _isComplete;
  16. protected bool _isPlaying;
  17. protected float _tempTimer;
  18. public bool IsLoop;
  19. public bool IsPlaying
  20. {
  21. get => _isPlaying;
  22. }
  23. protected float _curTime;
  24. /// <summary>
  25. /// 完成后是否自动销毁
  26. /// </summary>
  27. public bool AutoDispose = true;
  28. public void Pause()
  29. {
  30. _isPlaying = false;
  31. _isPause = true;
  32. }
  33. public void Play()
  34. {
  35. _isPlaying = true;
  36. _isPause = false;
  37. }
  38. public void Start()
  39. {
  40. _isPause = true;
  41. }
  42. public virtual void Update()
  43. {
  44. }
  45. /// <summary>
  46. /// 被杀死后补间将会被回收
  47. /// </summary>
  48. public async void Kill(bool isComplete = false)
  49. {
  50. if (_isKilled)
  51. {
  52. return;
  53. }
  54. if (isComplete)
  55. {
  56. OnCompleteAction?.Invoke();
  57. }
  58. _isKilled = true;
  59. Dispose();
  60. }
  61. public virtual void Dispose()
  62. {
  63. _tempTimer = 0;
  64. _curTime = 0;
  65. Duration = 0;
  66. _isPause = false;
  67. _isComplete = false;
  68. IsLoop = false;
  69. AutoDispose = true;
  70. OnCompleteAction = null;
  71. OnUpdateAction = null;
  72. OnUpdateAndValueAction = null;
  73. }
  74. }
  75. public delegate T CustomGetter<out T>();
  76. public delegate void CustomSetter<in T>(T pNewValue);
  77. }