123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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<CustomVectorTween> RuningVectorTweens = new List<CustomVectorTween>();
- public static Queue<CustomVectorTween> VectorTweenPool = new Queue<CustomVectorTween>();
- public static List<CustomFloatTween> RuningFloatTweens = new List<CustomFloatTween>();
- public static Queue<CustomFloatTween> FloatTweenPool = new Queue<CustomFloatTween>();
- public static void Init()
- {
- StaticUpdater.Instance.AddRenderUpdateCallBack(Update);
- }
- /// <summary>
- /// 创建一个tween
- /// </summary>
- /// <param name="getter"></param>
- /// <param name="setter"></param>
- /// <param name="endValue"></param>
- /// <param name="duration"></param>
- /// <param name="target">作用的目标 当目标不存在时tween会被自动回收</param>
- /// <returns></returns>
- public static CustomVectorTween To(CustomGetter<Vector2> getter, CustomSetter<Vector2> 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<float> getter, CustomSetter<float> 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);
- }
- }
- }
|