MoveVec.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using System;
  4. using System.Collections;
  5. public class MoveVec : Move
  6. {
  7. #region 变量
  8. protected float Timer;
  9. protected float Duration;
  10. protected Vector3 Delta;
  11. protected Vector3 Origin;
  12. protected Vector3 Destination;
  13. protected Transform Target;
  14. protected CurveFunctionV Func;
  15. #endregion
  16. public MoveVec(Transform target)
  17. {
  18. Target = target;
  19. }
  20. public override bool DoMove()
  21. {
  22. Timer += Time.fixedDeltaTime;
  23. if (Timer > Duration)
  24. {
  25. Target.position = Destination;
  26. Timer = 0;
  27. ManaAnim.MoveList.Remove(this);
  28. if (OnFinish != null)
  29. {
  30. OnFinish.Invoke();
  31. }
  32. return true;
  33. }
  34. else
  35. {
  36. Target.position = Func(Timer, Duration, Origin, Delta);
  37. return false;
  38. }
  39. }
  40. public void StartMove(Vector3 destination, float duration, Curve curve)
  41. {
  42. Finish = false;
  43. destination.z = Target.position.z;
  44. Delta = destination - Target.position;
  45. Origin = Target.position;
  46. Duration = duration;
  47. Destination = destination;
  48. Func = ManaAnim.FunctionDicV[curve];
  49. if (OnStart != null)
  50. {
  51. OnStart.Invoke();
  52. }
  53. ManaAnim.MoveList.Remove(this);
  54. ManaAnim.MoveList.Add(this);
  55. }
  56. }