Files
Syntriax.Engine/Engine.Systems/Tween/EngineExtensions/TweenAABB2DExtensions.cs

25 lines
891 B
C#

using Engine.Core;
namespace Engine.Systems.Tween;
public static class TweenAABB2DExtensions
{
private static readonly BoxedPool<AABB2D> boxedAABBPool = new(2);
public static ITween TweenAABB(this AABB2D initialAABB, ITweenManager tweenManager, float duration, AABB2D targetAABB, System.Action<AABB2D> setMethod)
{
Boxed<AABB2D> boxedInitial = boxedAABBPool.Get(initialAABB);
Boxed<AABB2D> boxedTarget = boxedAABBPool.Get(targetAABB);
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(new AABB2D(boxedInitial.Value.LowerBoundary.Lerp(boxedTarget.Value.LowerBoundary, t), boxedInitial.Value.UpperBoundary.Lerp(boxedTarget.Value.UpperBoundary, t))));
tween.OnComplete(() =>
{
boxedAABBPool.Return(boxedInitial);
boxedAABBPool.Return(boxedTarget);
});
return tween;
}
}