MoveRoot.cs 2.1 KB

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