108 lines
4.9 KiB
C#
108 lines
4.9 KiB
C#
using Syntriax.Engine.Core;
|
|
|
|
namespace Syntriax.Engine.Systems.Tween;
|
|
|
|
public static class TweenTransform2DExtensions
|
|
{
|
|
public static ITween TweenPosition(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetPosition)
|
|
{
|
|
Vector2D initialPosition = transform2D.Position;
|
|
return tweenManager.StartTween(duration, t => transform2D.Position = initialPosition.Lerp(targetPosition, t));
|
|
}
|
|
|
|
public static ITween TweenScale(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetScale)
|
|
{
|
|
Vector2D initialScale = transform2D.Scale;
|
|
return tweenManager.StartTween(duration, t => transform2D.Scale = initialScale.Lerp(targetScale, t));
|
|
}
|
|
|
|
public static ITween TweenRotation(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float targetRotation)
|
|
{
|
|
float initialRotation = transform2D.Rotation;
|
|
return tweenManager.StartTween(duration, t => transform2D.Rotation = initialRotation.Lerp(targetRotation, t));
|
|
}
|
|
|
|
public static ITween TweenLocalPosition(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetLocalPosition)
|
|
{
|
|
Vector2D initialLocalPosition = transform2D.LocalPosition;
|
|
return tweenManager.StartTween(duration, t => transform2D.LocalPosition = initialLocalPosition.Lerp(targetLocalPosition, t));
|
|
}
|
|
|
|
public static ITween TweenLocalScale(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetLocalScale)
|
|
{
|
|
Vector2D initialLocalScale = transform2D.LocalScale;
|
|
return tweenManager.StartTween(duration, t => transform2D.LocalScale = initialLocalScale.Lerp(targetLocalScale, t));
|
|
}
|
|
|
|
public static ITween TweenLocalRotation(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float targetLocalRotation)
|
|
{
|
|
float initialLocalRotation = transform2D.LocalRotation;
|
|
return tweenManager.StartTween(duration, t => transform2D.LocalRotation = initialLocalRotation.Lerp(targetLocalRotation, t));
|
|
}
|
|
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;
|
|
});
|
|
}
|
|
}
|