using Engine.Core; namespace Engine.Systems.Tween; public static class TweenColorExtensions { private static readonly BoxedPool boxedColorHSVPool = new(2); private static readonly BoxedPool boxedColorHSVAPool = new(2); public static ITween TweenColor(this ColorRGB initialColorRGB, ITweenManager tweenManager, float duration, ColorRGB targetColorRGB, System.Action setMethod) => TweenColor((ColorHSV)initialColorRGB, tweenManager, duration, (ColorHSV)targetColorRGB, color => setMethod?.Invoke(color)); public static ITween TweenColor(this ColorRGBA initialColorRGBA, ITweenManager tweenManager, float duration, ColorRGBA targetColorRGBA, System.Action setMethod) => TweenColor((ColorHSVA)initialColorRGBA, tweenManager, duration, (ColorHSVA)targetColorRGBA, color => setMethod?.Invoke(color)); public static ITween TweenColor(this ColorHSV initialColorHSV, ITweenManager tweenManager, float duration, ColorHSV targetColorHSV, System.Action setMethod) { Boxed boxedInitial = boxedColorHSVPool.Get(initialColorHSV); Boxed boxedTarget = boxedColorHSVPool.Get(targetColorHSV); ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t))); tween.OnComplete(() => { boxedColorHSVPool.Return(boxedInitial); boxedColorHSVPool.Return(boxedTarget); }); return tween; } public static ITween TweenColor(this ColorHSVA initialColorHSVA, ITweenManager tweenManager, float duration, ColorHSVA targetColorHSVA, System.Action setMethod) { Boxed boxedInitial = boxedColorHSVAPool.Get(initialColorHSVA); Boxed boxedTarget = boxedColorHSVAPool.Get(targetColorHSVA); ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t))); tween.OnComplete(() => { boxedColorHSVAPool.Return(boxedInitial); boxedColorHSVAPool.Return(boxedTarget); }); return tween; } }