using System; using System.Collections.Generic; using Fort23.Core; using UnityEngine; using Utility.UITool; using Object = UnityEngine.Object; namespace Utility.CTween { public static class CustomTweenManager { public static AnimationCurveLibrary AnimationCurveLibrary { get { return AnimationCurveManager.Instance.AnimationCurveLibrary; } } private static int FPS = 30; public static List RuningVectorTweens = new List(); public static Queue VectorTweenPool = new Queue(); public static List RuningFloatTweens = new List(); public static Queue FloatTweenPool = new Queue(); public static void Init() { StaticUpdater.Instance.AddRenderUpdateCallBack(Update); } /// /// 创建一个tween /// /// /// /// /// /// 作用的目标 当目标不存在时tween会被自动回收 /// public static CustomVectorTween To(CustomGetter getter, CustomSetter setter, Vector2 endValue, float duration, GameObject target) { CustomVectorTween customVectorTween; if (VectorTweenPool.Count > 0) { customVectorTween = VectorTweenPool.Dequeue(); } else { customVectorTween = new CustomVectorTween(); } customVectorTween.CustomInit(getter, setter, endValue, duration, target); RuningVectorTweens.Add(customVectorTween); return customVectorTween; } public static CustomFloatTween To(CustomGetter getter, CustomSetter setter, float endValue, float duration, GameObject target) { CustomFloatTween customFloatTween; if (FloatTweenPool.Count > 0) { customFloatTween = FloatTweenPool.Dequeue(); } else { customFloatTween = new CustomFloatTween(); } customFloatTween.CustomInit(getter, setter, endValue, duration, target); RuningFloatTweens.Add(customFloatTween); return customFloatTween; } public static void Update() { for (var i = 0; i < RuningVectorTweens.Count; i++) { RuningVectorTweens[i].Update(); } for (var i = 0; i < RuningFloatTweens.Count; i++) { RuningFloatTweens[i].Update(); } } public static void VectorRecycle(CustomVectorTween customVectorTween) { RuningVectorTweens.Remove(customVectorTween); //VectorTweenPool.Enqueue(customVectorTween); } public static void FloatRecycle(CustomFloatTween customFloatTween) { RuningFloatTweens.Remove(customFloatTween); // FloatTweenPool.Enqueue(customFloatTween); } } }