MoveRoot.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using System.Collections;
  4. public abstract class MoveRoot
  5. {
  6. #region 变量
  7. public bool IsPlaying
  8. {
  9. get { return AnimManager.MoveForList.Contains(this) || AnimManager.MoveBacList.Contains(this); }
  10. }
  11. public virtual bool InDestination
  12. {
  13. get { return InDestination_; }
  14. set { InDestination_ = value; }
  15. }
  16. public bool InDestination_;
  17. public bool InPause;
  18. public UnityAction OnForwardStart;
  19. public UnityAction OnForwardFinish;
  20. #endregion
  21. public abstract bool DoForward();
  22. public abstract bool DoBackward();
  23. public virtual void Pause()
  24. {
  25. if (!InPause)
  26. {
  27. InPause = true;
  28. AnimManager.MoveForList.Remove(this);
  29. }
  30. }
  31. public virtual void Resume()
  32. {
  33. if (InPause)
  34. {
  35. InPause = false;
  36. AnimManager.MoveForList.Add(this);
  37. }
  38. }
  39. public virtual void PushEvent(EventType type, UnityAction action)
  40. {
  41. if (type == EventType.ForwardStart)
  42. {
  43. OnForwardStart = action + OnForwardStart;
  44. }
  45. else if (type == EventType.ForwardFinish)
  46. {
  47. OnForwardFinish = action + OnForwardFinish;
  48. }
  49. }
  50. public virtual void AddEventOnetime(EventType type, UnityAction action)
  51. {
  52. if (type == EventType.ForwardStart)
  53. {
  54. action += () =>
  55. {
  56. OnForwardStart -= action;
  57. };
  58. OnForwardStart += action;
  59. }
  60. else if (type == EventType.ForwardFinish)
  61. {
  62. action += () =>
  63. {
  64. OnForwardFinish -= action;
  65. };
  66. OnForwardFinish += action;
  67. }
  68. }
  69. public virtual void PushEventOnetime(EventType type, UnityAction action)
  70. {
  71. if (type == EventType.ForwardStart)
  72. {
  73. action += () =>
  74. {
  75. OnForwardStart -= action;
  76. };
  77. OnForwardStart = action + OnForwardStart;
  78. }
  79. else if (type == EventType.ForwardFinish)
  80. {
  81. action += () =>
  82. {
  83. OnForwardFinish -= action;
  84. };
  85. OnForwardFinish = action + OnForwardFinish;
  86. }
  87. }
  88. }