32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using Engine.Core;
|
|
|
|
namespace Engine.Systems.Tween;
|
|
|
|
public static class TweenSphere3DExtensions
|
|
{
|
|
private static readonly BoxedPool<Sphere3D> boxedSphere3DPool = new(2);
|
|
|
|
public static ITween TweenSphere3D(this Sphere3D initialSphere3D, ITweenManager tweenManager, float duration, Sphere3D targetSphere3D, System.Action<Sphere3D> setMethod)
|
|
{
|
|
Boxed<Sphere3D> boxedInitial = boxedSphere3DPool.Get(initialSphere3D);
|
|
Boxed<Sphere3D> boxedTarget = boxedSphere3DPool.Get(targetSphere3D);
|
|
|
|
ITween tween = tweenManager.StartTween(duration,
|
|
t => setMethod?.Invoke(
|
|
new Sphere3D(
|
|
boxedInitial.Value.Center.Lerp(boxedTarget.Value.Center, t),
|
|
boxedInitial.Value.Diameter.Lerp(boxedTarget.Value.Diameter, t)
|
|
)
|
|
)
|
|
);
|
|
|
|
tween.OnComplete(() =>
|
|
{
|
|
boxedSphere3DPool.Return(boxedInitial);
|
|
boxedSphere3DPool.Return(boxedTarget);
|
|
});
|
|
|
|
return tween;
|
|
}
|
|
}
|