TweenGra.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  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. if (target.color == origin)
  17. {
  18. InForward = true;
  19. }
  20. else if (target.color == destination)
  21. {
  22. InBackward = true;
  23. }
  24. Func = ManaAnim.FunctionDicC[curve];
  25. Target = target;
  26. IsForward = false;
  27. IsBackward = false;
  28. Delta = destination - origin;
  29. Origin = origin;
  30. Duration = duration;
  31. DestActive = destActive;
  32. Destination = destination;
  33. OriginActive = originActive;
  34. OnForwardStart += () =>
  35. {
  36. Target.SetActive(true);
  37. };
  38. OnForwardFinish += () =>
  39. {
  40. Target.SetActive(DestActive);
  41. };
  42. OnBackwardStart += () =>
  43. {
  44. Target.SetActive(true);
  45. };
  46. OnBackwardFinish += () =>
  47. {
  48. Target.SetActive(OriginActive);
  49. };
  50. }
  51. public override void StartForward()
  52. {
  53. base.StartForward();
  54. if (IsBackward)
  55. {
  56. Timer = Duration - Timer;
  57. }
  58. else
  59. {
  60. Target.color = Origin;
  61. }
  62. }
  63. public override void StartBackward()
  64. {
  65. base.StartBackward();
  66. if (IsForward)
  67. {
  68. Timer = Duration - Timer;
  69. }
  70. else
  71. {
  72. Target.color = Destination;
  73. }
  74. }
  75. public override bool DoForward()
  76. {
  77. Timer += Time.fixedDeltaTime;
  78. if (Timer > Duration)
  79. {
  80. Timer = 0;
  81. Target.color = Destination;
  82. IsForward = false;
  83. InBackward = true;
  84. OnForwardFinish.Invoke();
  85. ManaAnim.TweenForList.Remove(this);
  86. return true;
  87. }
  88. else
  89. {
  90. Target.color = Func(Timer, Duration, Origin, Delta);
  91. return false;
  92. }
  93. }
  94. public override bool DoBackward()
  95. {
  96. Timer += Time.fixedDeltaTime;
  97. if (Timer > Duration)
  98. {
  99. Timer = 0;
  100. Target.color = Origin;
  101. IsBackward = false;
  102. InForward = true;
  103. OnBackwardFinish.Invoke();
  104. ManaAnim.TweenBacList.Remove(this);
  105. return true;
  106. }
  107. else
  108. {
  109. Target.color = Func(Timer, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a));
  110. return false;
  111. }
  112. }
  113. }