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

25 lines
891 B
C#

using Engine.Core;
namespace Engine.Systems.Tween;
public static class TweenAABB3DExtensions
{
private static readonly BoxedPool<AABB3D> boxedAABBPool = new(2);
public static ITween TweenAABB(this AABB3D initialAABB, ITweenManager tweenManager, float duration, AABB3D targetAABB, System.Action<AABB3D> setMethod)
{
Boxed<AABB3D> boxedInitial = boxedAABBPool.Get(initialAABB);
Boxed<AABB3D> boxedTarget = boxedAABBPool.Get(targetAABB);
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(new AABB3D(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;
}
}