Move.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Events;
  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 PushEvent(EventType type, UnityAction action)
  18. {
  19. if (type == EventType.ForwardStart)
  20. {
  21. OnForwardStart = action + OnForwardStart;
  22. }
  23. else if (type == EventType.ForwardFinish)
  24. {
  25. OnForwardFinish = action + OnForwardFinish;
  26. }
  27. }
  28. public void AddEventOnetime(EventType type, UnityAction action)
  29. {
  30. if (type == EventType.ForwardStart)
  31. {
  32. action += () =>
  33. {
  34. OnForwardStart -= action;
  35. };
  36. OnForwardStart += action;
  37. }
  38. else if (type == EventType.ForwardFinish)
  39. {
  40. action += () =>
  41. {
  42. OnForwardFinish -= action;
  43. };
  44. OnForwardFinish += action;
  45. }
  46. }
  47. public void PushEventOnetime(EventType type, UnityAction action)
  48. {
  49. if (type == EventType.ForwardStart)
  50. {
  51. action += () =>
  52. {
  53. OnForwardStart -= action;
  54. };
  55. OnForwardStart = action + OnForwardStart;
  56. }
  57. else if (type == EventType.ForwardFinish)
  58. {
  59. action += () =>
  60. {
  61. OnForwardFinish -= action;
  62. };
  63. OnForwardFinish = action + OnForwardFinish;
  64. }
  65. }
  66. }