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
		
			
				
	
	
		
			91 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using Engine.Core;
 | 
						|
 | 
						|
namespace Engine.Systems.Tween;
 | 
						|
 | 
						|
public static class TweenTransform2DExtensions
 | 
						|
{
 | 
						|
    public static ITween TweenPosition(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetPosition)
 | 
						|
        => transform2D.Position.TweenVector2D(tweenManager, duration, targetPosition, x => transform2D.Position = x);
 | 
						|
 | 
						|
    public static ITween TweenScale(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetScale)
 | 
						|
        => transform2D.Scale.TweenVector2D(tweenManager, duration, targetScale, x => transform2D.Scale = x);
 | 
						|
 | 
						|
    public static ITween TweenRotation(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float targetRotation)
 | 
						|
        => transform2D.Rotation.TweenFloat(tweenManager, duration, targetRotation, x => transform2D.Rotation = x);
 | 
						|
 | 
						|
    public static ITween TweenLocalPosition(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetLocalPosition)
 | 
						|
        => transform2D.LocalPosition.TweenVector2D(tweenManager, duration, targetLocalPosition, x => transform2D.LocalPosition = x);
 | 
						|
 | 
						|
    public static ITween TweenLocalScale(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetLocalScale)
 | 
						|
        => transform2D.LocalScale.TweenVector2D(tweenManager, duration, targetLocalScale, x => transform2D.LocalScale = x);
 | 
						|
 | 
						|
    public static ITween TweenLocalRotation(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float targetLocalRotation)
 | 
						|
        => transform2D.LocalRotation.TweenFloat(tweenManager, duration, targetLocalRotation, x => transform2D.LocalRotation = x);
 | 
						|
 | 
						|
    public static ITween TweenPositionAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additivePosition)
 | 
						|
    {
 | 
						|
        Vector2D progressedPosition = Vector2D.Zero;
 | 
						|
        return tweenManager.StartTween(duration, t =>
 | 
						|
        {
 | 
						|
            Vector2D displacement = Vector2D.Zero.Lerp(additivePosition, t) - progressedPosition;
 | 
						|
            transform2D.Position += displacement;
 | 
						|
            progressedPosition += displacement;
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
    public static ITween TweenScaleAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additiveScale)
 | 
						|
    {
 | 
						|
        Vector2D progressedScale = Vector2D.Zero;
 | 
						|
        return tweenManager.StartTween(duration, t =>
 | 
						|
        {
 | 
						|
            Vector2D displacement = Vector2D.Zero.Lerp(additiveScale, t) - progressedScale;
 | 
						|
            transform2D.Scale += displacement;
 | 
						|
            progressedScale += displacement;
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
    public static ITween TweenRotationAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float additiveRotation)
 | 
						|
    {
 | 
						|
        float progressedRotation = 0f;
 | 
						|
        return tweenManager.StartTween(duration, t =>
 | 
						|
        {
 | 
						|
            float displacement = 0f.Lerp(additiveRotation, t) - progressedRotation;
 | 
						|
            transform2D.Rotation += displacement;
 | 
						|
            progressedRotation += displacement;
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
    public static ITween TweenLocalPositionAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additiveLocalPosition)
 | 
						|
    {
 | 
						|
        Vector2D progressedLocalPosition = Vector2D.Zero;
 | 
						|
        return tweenManager.StartTween(duration, t =>
 | 
						|
        {
 | 
						|
            Vector2D displacement = Vector2D.Zero.Lerp(additiveLocalPosition, t) - progressedLocalPosition;
 | 
						|
            transform2D.LocalPosition += displacement;
 | 
						|
            progressedLocalPosition += displacement;
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
    public static ITween TweenLocalScaleAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D additiveLocalScale)
 | 
						|
    {
 | 
						|
        Vector2D progressedLocalScale = Vector2D.Zero;
 | 
						|
        return tweenManager.StartTween(duration, t =>
 | 
						|
        {
 | 
						|
            Vector2D displacement = Vector2D.Zero.Lerp(additiveLocalScale, t) - progressedLocalScale;
 | 
						|
            transform2D.LocalScale += displacement;
 | 
						|
            progressedLocalScale += displacement;
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
    public static ITween TweenLocalRotationAdditive(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float additiveLocalRotation)
 | 
						|
    {
 | 
						|
        float progressedLocalRotation = 0f;
 | 
						|
        return tweenManager.StartTween(duration, t =>
 | 
						|
        {
 | 
						|
            float displacement = 0f.Lerp(additiveLocalRotation, t) - progressedLocalRotation;
 | 
						|
            transform2D.LocalRotation += displacement;
 | 
						|
            progressedLocalRotation += displacement;
 | 
						|
        });
 | 
						|
    }
 | 
						|
}
 |