TweenCG.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. public class TweenCG : Tween
  5. {
  6. #region 变量
  7. protected float Delta;
  8. protected float Origin;
  9. protected float Destination;
  10. protected CanvasGroup Target;
  11. protected CurveFunctionF Func;
  12. #endregion
  13. public TweenCG(CanvasGroup target, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve)
  14. {
  15. Target = target;
  16. Duration = duration;
  17. DestActive = destActive;
  18. OriginActive = originActive;
  19. Delta = destination - origin;
  20. Origin = origin;
  21. Destination = destination;
  22. OnForwardStart += () =>
  23. {
  24. Target.SetActive(true);
  25. Target.interactable = false;
  26. };
  27. OnForwardFinish += () =>
  28. {
  29. Target.SetActive(DestActive);
  30. Target.interactable = DestActive;
  31. };
  32. OnBackwardStart += () =>
  33. {
  34. Target.SetActive(true);
  35. Target.interactable = false;
  36. };
  37. OnBackwardFinish += () =>
  38. {
  39. Target.SetActive(OriginActive);
  40. Target.interactable = OriginActive;
  41. };
  42. Func = ManaAnim.FunctionDicF[curve];
  43. }
  44. public override bool DoForward()
  45. {
  46. if (Timer > Duration)
  47. {
  48. Target.alpha = Destination;
  49. Timer = 0;
  50. IsBackwardFinish = true;
  51. OnForwardFinish.Invoke();
  52. ManaAnim.TweenForList.Remove(this);
  53. return true;
  54. }
  55. else
  56. {
  57. Target.alpha = Func(Timer, Duration, Origin, Delta);
  58. Timer += Time.fixedDeltaTime;
  59. return false;
  60. }
  61. }
  62. public override bool DoBackward()
  63. {
  64. if (Timer > Duration)
  65. {
  66. Target.alpha = Origin;
  67. Timer = 0;
  68. IsForwardFinish = true;
  69. OnBackwardFinish.Invoke();
  70. ManaAnim.TweenBacList.Remove(this);
  71. return true;
  72. }
  73. else
  74. {
  75. Target.alpha = Func(Timer, Duration, Destination, -Delta);
  76. Timer += Time.fixedDeltaTime;
  77. return false;
  78. }
  79. }
  80. }