Shake.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. if (OnForwardFinish != null)
  52. {
  53. OnForwardFinish.Invoke();
  54. }
  55. return true;
  56. }
  57. else
  58. {
  59. Target.position = Func(Timer, Duration, Repeat, Origin, Strength);
  60. Target.SetZ(Z);
  61. return false;
  62. }
  63. }
  64. public void StartShake(int repeat, float duration, Vector3 strength, Curve curve)
  65. {
  66. InDestination = false;
  67. Repeat = repeat;
  68. Z = Target.position.z;
  69. Origin = Target.position;
  70. Strength = strength;
  71. Duration = duration;
  72. Func = ManaAnim.ShakeFuncDicV[curve];
  73. if (OnForwardStart != null)
  74. {
  75. OnForwardStart.Invoke();
  76. }
  77. ManaAnim.MoveList.Remove(this);
  78. ManaAnim.MoveList.Add(this);
  79. }
  80. }