They still do generate a lot of garbage but with boxed value pools I made the boxes reusable, it still does generate garbage through the delegate creation, gotta find a solution for them later
32 lines
996 B
C#
32 lines
996 B
C#
using Engine.Core;
|
|
|
|
namespace Engine.Systems.Tween;
|
|
|
|
public static class TweenCircleExtensions
|
|
{
|
|
private static readonly BoxedPool<Circle> boxedCirclePool = new(2);
|
|
|
|
public static ITween TweenCircle(this Circle initialCircle, ITweenManager tweenManager, float duration, Circle targetCircle, System.Action<Circle> setMethod)
|
|
{
|
|
Boxed<Circle> boxedInitial = boxedCirclePool.Get(initialCircle);
|
|
Boxed<Circle> boxedTarget = boxedCirclePool.Get(targetCircle);
|
|
|
|
ITween tween = tweenManager.StartTween(duration,
|
|
t => setMethod?.Invoke(
|
|
new Circle(
|
|
boxedInitial.Value.Center.Lerp(boxedTarget.Value.Center, t),
|
|
boxedInitial.Value.Diameter.Lerp(boxedTarget.Value.Diameter, t)
|
|
)
|
|
)
|
|
);
|
|
|
|
tween.OnComplete(() =>
|
|
{
|
|
boxedCirclePool.Return(boxedInitial);
|
|
boxedCirclePool.Return(boxedTarget);
|
|
});
|
|
|
|
return tween;
|
|
}
|
|
}
|