Shake.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using Debug = System.Diagnostics.Debug;
  6. public class Shake : MoveRoot
  7. {
  8. #region 变量
  9. public override bool InDestination
  10. {
  11. get
  12. {
  13. if (Target.position.Equal(Origin))
  14. {
  15. InDestination_ = true;
  16. }
  17. else
  18. {
  19. InDestination_ = false;
  20. }
  21. return InDestination_;
  22. }
  23. set
  24. {
  25. InDestination_ = value;
  26. InPause = false;
  27. if (InDestination_)
  28. {
  29. Target.position = Origin;
  30. }
  31. }
  32. }
  33. public int Repeat;
  34. public float Z;
  35. public float Timer;
  36. public float Duration;
  37. public Vector3 Origin;
  38. public Vector3 Strength;
  39. public Transform Target;
  40. public ShakeFunctionV Func;
  41. #endregion
  42. public Shake(Transform transform)
  43. {
  44. Target = transform;
  45. }
  46. public override bool DoForward()
  47. {
  48. Timer += Time.fixedDeltaTime;
  49. if (Timer > Duration)
  50. {
  51. Timer = 0;
  52. InDestination = true;
  53. if (OnForwardFinish != null)
  54. {
  55. OnForwardFinish.Invoke();
  56. }
  57. return true;
  58. }
  59. else
  60. {
  61. Target.position = Func(Timer, Duration, Repeat, Origin, Strength);
  62. Target.SetZ(Z);
  63. return false;
  64. }
  65. }
  66. public override bool DoBackward()
  67. {
  68. throw new Exception();
  69. }
  70. public void StartShake(int repeat, float duration, Vector3 strength, Curve curve)
  71. {
  72. Timer = 0;
  73. InDestination = false;
  74. Repeat = repeat;
  75. Z = Target.position.z;
  76. Origin = Target.position;
  77. Strength = strength;
  78. Duration = duration;
  79. Func = ManaAnim.ShakeFuncDicV[curve];
  80. OnForwardStart.SafeInvoke();
  81. ManaAnim.MoveForList.Remove(this);
  82. ManaAnim.MoveForList.Add(this);
  83. }
  84. }