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

32 lines
991 B
C#

using Engine.Core;
namespace Engine.Systems.Tween;
public static class TweenRay2DExtensions
{
private static readonly BoxedPool<Ray2D> boxedRay2DPool = new(2);
public static ITween TweenRay2D(this Ray2D initialRay2D, ITweenManager tweenManager, float duration, Ray2D targetRay2D, System.Action<Ray2D> setMethod)
{
Boxed<Ray2D> boxedInitial = boxedRay2DPool.Get(initialRay2D);
Boxed<Ray2D> boxedTarget = boxedRay2DPool.Get(targetRay2D);
ITween tween = tweenManager.StartTween(duration,
t => setMethod?.Invoke(
new Ray2D(
boxedInitial.Value.Origin.Lerp(boxedTarget.Value.Origin, t),
boxedInitial.Value.Direction.Lerp(boxedTarget.Value.Direction, t).Normalized
)
)
);
tween.OnComplete(() =>
{
boxedRay2DPool.Return(boxedInitial);
boxedRay2DPool.Return(boxedTarget);
});
return tween;
}
}