TweenGra.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System.Collections;
  5. public class TweenGra : Tween
  6. {
  7. #region 变量
  8. protected Color Delta;
  9. protected Color Origin;
  10. protected Color Destination;
  11. protected Graphic Target;
  12. protected CurveFunctionC Func;
  13. #endregion
  14. public TweenGra(Graphic target, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve)
  15. {
  16. Target = target;
  17. IsForward = false;
  18. IsBackward = false;
  19. Duration = duration;
  20. DestActive = destActive;
  21. OriginActive = originActive;
  22. Delta = destination - origin;
  23. Origin = origin;
  24. Destination = destination;
  25. OnForwardStart += () =>
  26. {
  27. Target.SetActive(true);
  28. };
  29. OnForwardFinish += () =>
  30. {
  31. Target.SetActive(DestActive);
  32. };
  33. OnBackwardStart += () =>
  34. {
  35. Target.SetActive(true);
  36. };
  37. OnBackwardFinish += () =>
  38. {
  39. Target.SetActive(OriginActive);
  40. };
  41. Func = ManaAnim.FunctionDicC[curve];
  42. }
  43. public override void StartForward()
  44. {
  45. base.StartForward();
  46. if (IsBackward)
  47. {
  48. Timer = Duration - Timer;
  49. }
  50. }
  51. public override void StartBackward()
  52. {
  53. base.StartBackward();
  54. if (IsForward)
  55. {
  56. Timer = Duration - Timer;
  57. }
  58. }
  59. public override bool DoForward()
  60. {
  61. Timer += Time.fixedDeltaTime;
  62. if (Timer > Duration)
  63. {
  64. Target.color = Destination;
  65. Timer = 0;
  66. IsForward = false;
  67. OnForwardFinish.Invoke();
  68. ManaAnim.TweenForList.Remove(this);
  69. return true;
  70. }
  71. else
  72. {
  73. Target.color = Func(Timer, Duration, Origin, Delta);
  74. return false;
  75. }
  76. }
  77. public override bool DoBackward()
  78. {
  79. Timer += Time.fixedDeltaTime;
  80. if (Timer > Duration)
  81. {
  82. Target.color = Origin;
  83. Timer = 0;
  84. IsBackward = false;
  85. OnBackwardFinish.Invoke();
  86. ManaAnim.TweenBacList.Remove(this);
  87. return true;
  88. }
  89. else
  90. {
  91. Target.color = Func(Timer, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a));
  92. return false;
  93. }
  94. }
  95. }