using Engine.Core; namespace Engine.Systems.Tween; public static class TweenPrimitiveExtensions { private static readonly BoxedPool boxedFloatPool = new(2); private static readonly BoxedPool boxedIntPool = new(2); public static ITween TweenFloat(this float initialFloat, ITweenManager tweenManager, float duration, float targetFloat, System.Action setMethod) { Boxed boxedInitial = boxedFloatPool.Get(initialFloat); Boxed boxedTarget = boxedFloatPool.Get(targetFloat); ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t))); tween.OnComplete(() => { boxedFloatPool.Return(boxedInitial); boxedFloatPool.Return(boxedTarget); }); return tween; } public static ITween TweenInt(this int initialInt, ITweenManager tweenManager, float duration, int targetInt, System.Action setMethod) { Boxed boxedInitial = boxedIntPool.Get(initialInt); Boxed boxedTarget = boxedIntPool.Get(targetInt); ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value + (boxedTarget.Value - boxedInitial.Value) * t)); tween.OnComplete(() => { boxedIntPool.Return(boxedInitial); boxedIntPool.Return(boxedTarget); }); return tween; } }