using Engine.Core; namespace Engine.Systems.Tween; public static class TweenVector2DExtensions { private static readonly BoxedPool boxedVector2DPool = new(2); public static ITween TweenVector2D(this Vector2D initialVector2D, ITweenManager tweenManager, float duration, Vector2D targetVector2D, System.Action setMethod) { Boxed boxedInitial = boxedVector2DPool.Get(initialVector2D); Boxed boxedTarget = boxedVector2DPool.Get(targetVector2D); ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t))); tween.OnComplete(() => { boxedVector2DPool.Return(boxedInitial); boxedVector2DPool.Return(boxedTarget); }); return tween; } }