Move.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using System;
  4. using System.Collections;
  5. public class Move : Anim
  6. {
  7. #region 变量
  8. protected override bool InDestination
  9. {
  10. get
  11. {
  12. if (Target.position == Destination)
  13. {
  14. _InDestination = true;
  15. }
  16. else
  17. {
  18. _InDestination = false;
  19. }
  20. return _InDestination;
  21. }
  22. set
  23. {
  24. _InDestination = value;
  25. if (_InDestination)
  26. {
  27. Target.position = Destination;
  28. }
  29. }
  30. }
  31. protected float Timer;
  32. protected float Duration;
  33. protected Vector3 Delta;
  34. protected Vector3 Origin;
  35. protected Vector3 Destination;
  36. protected Transform Target;
  37. protected CurveFunctionV Func;
  38. #endregion
  39. public Move(Transform target)
  40. {
  41. Target = target;
  42. }
  43. public override bool Do()
  44. {
  45. Timer += Time.fixedDeltaTime;
  46. if (Timer > Duration)
  47. {
  48. Timer = 0;
  49. Target.position = Destination;
  50. ManaAnim.AnimList.Remove(this);
  51. if (OnFinish != null)
  52. {
  53. OnFinish.Invoke();
  54. }
  55. return true;
  56. }
  57. else
  58. {
  59. Target.position = Func(Timer, Duration, Origin, Delta);
  60. return false;
  61. }
  62. }
  63. public void StartMove(Vector3 destination, float duration, Curve curve)
  64. {
  65. InDestination = false;
  66. destination.z = Target.position.z;
  67. Delta = destination - Target.position;
  68. Origin = Target.position;
  69. Duration = duration;
  70. Destination = destination;
  71. Func = ManaAnim.CurveFunctionDicV[curve];
  72. if (OnStart != null)
  73. {
  74. OnStart.Invoke();
  75. }
  76. ManaAnim.AnimList.Remove(this);
  77. ManaAnim.AnimList.Add(this);
  78. }
  79. }