CustomTweenManager.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using Fort23.Core;
  4. using UnityEngine;
  5. using Utility.UITool;
  6. using Object = UnityEngine.Object;
  7. namespace Utility.CTween
  8. {
  9. public static class CustomTweenManager
  10. {
  11. public static AnimationCurveLibrary AnimationCurveLibrary
  12. {
  13. get { return AnimationCurveManager.Instance.AnimationCurveLibrary; }
  14. }
  15. private static int FPS = 30;
  16. public static List<CustomVectorTween> RuningVectorTweens = new List<CustomVectorTween>();
  17. public static Queue<CustomVectorTween> VectorTweenPool = new Queue<CustomVectorTween>();
  18. public static List<CustomFloatTween> RuningFloatTweens = new List<CustomFloatTween>();
  19. public static Queue<CustomFloatTween> FloatTweenPool = new Queue<CustomFloatTween>();
  20. public static void Init()
  21. {
  22. StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
  23. }
  24. /// <summary>
  25. /// 创建一个tween
  26. /// </summary>
  27. /// <param name="getter"></param>
  28. /// <param name="setter"></param>
  29. /// <param name="endValue"></param>
  30. /// <param name="duration"></param>
  31. /// <param name="target">作用的目标 当目标不存在时tween会被自动回收</param>
  32. /// <returns></returns>
  33. public static CustomVectorTween To(CustomGetter<Vector2> getter, CustomSetter<Vector2> setter, Vector2 endValue, float duration, GameObject target)
  34. {
  35. CustomVectorTween customVectorTween;
  36. if (VectorTweenPool.Count > 0)
  37. {
  38. customVectorTween = VectorTweenPool.Dequeue();
  39. }
  40. else
  41. {
  42. customVectorTween = new CustomVectorTween();
  43. }
  44. customVectorTween.CustomInit(getter, setter, endValue, duration, target);
  45. RuningVectorTweens.Add(customVectorTween);
  46. return customVectorTween;
  47. }
  48. public static CustomFloatTween To(CustomGetter<float> getter, CustomSetter<float> setter, float endValue, float duration, GameObject target)
  49. {
  50. CustomFloatTween customFloatTween;
  51. if (FloatTweenPool.Count > 0)
  52. {
  53. customFloatTween = FloatTweenPool.Dequeue();
  54. }
  55. else
  56. {
  57. customFloatTween = new CustomFloatTween();
  58. }
  59. customFloatTween.CustomInit(getter, setter, endValue, duration, target);
  60. RuningFloatTweens.Add(customFloatTween);
  61. return customFloatTween;
  62. }
  63. public static void Update()
  64. {
  65. for (var i = 0; i < RuningVectorTweens.Count; i++)
  66. {
  67. RuningVectorTweens[i].Update();
  68. }
  69. for (var i = 0; i < RuningFloatTweens.Count; i++)
  70. {
  71. RuningFloatTweens[i].Update();
  72. }
  73. }
  74. public static void VectorRecycle(CustomVectorTween customVectorTween)
  75. {
  76. RuningVectorTweens.Remove(customVectorTween);
  77. //VectorTweenPool.Enqueue(customVectorTween);
  78. }
  79. public static void FloatRecycle(CustomFloatTween customFloatTween)
  80. {
  81. RuningFloatTweens.Remove(customFloatTween);
  82. // FloatTweenPool.Enqueue(customFloatTween);
  83. }
  84. }
  85. }