Shake.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Debug = System.Diagnostics.Debug;
  5. public class Shake : Move
  6. {
  7. #region 变量
  8. protected override bool InDestination
  9. {
  10. get
  11. {
  12. if (Target.position == Origin)
  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 = Origin;
  28. }
  29. }
  30. }
  31. protected int Repeat;
  32. protected float Z;
  33. protected float Timer;
  34. protected float Duration;
  35. protected Vector3 Origin;
  36. protected Vector3 Strength;
  37. protected Transform Target;
  38. protected ShakeFunctionV Func;
  39. #endregion
  40. public Shake(Transform transform)
  41. {
  42. Target = transform;
  43. }
  44. public override bool Do()
  45. {
  46. Timer += Time.fixedDeltaTime;
  47. if (Timer > Duration)
  48. {
  49. Timer = 0;
  50. InDestination = true;
  51. ManaAnim.MoveList.Remove(this);
  52. if (OnForwardFinish != null)
  53. {
  54. OnForwardFinish.Invoke();
  55. }
  56. return true;
  57. }
  58. else
  59. {
  60. Target.position = Func(Timer, Duration, Repeat, Origin, Strength);
  61. Target.SetZ(Z);
  62. return false;
  63. }
  64. }
  65. public void StartShake(int repeat, float duration, Vector3 strength, Curve curve)
  66. {
  67. InDestination = false;
  68. Repeat = repeat;
  69. Z = Target.position.z;
  70. Origin = Target.position;
  71. Strength = strength;
  72. Duration = duration;
  73. Func = ManaAnim.ShakeFuncDicV[curve];
  74. if (OnForwardStart != null)
  75. {
  76. OnForwardStart.Invoke();
  77. }
  78. ManaAnim.MoveList.Remove(this);
  79. ManaAnim.MoveList.Add(this);
  80. }
  81. }