Move.cs 1.9 KB

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