feat: added engine member tween extensions
This commit is contained in:
		
							
								
								
									
										10
									
								
								Engine.Systems/Tween/EngineExtensions/TweenAABBExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Engine.Systems/Tween/EngineExtensions/TweenAABBExtensions.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenAABBExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenAABB(this AABB initialAABB, ITweenManager tweenManager, float duration, AABB targetAABB, Action<AABB> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(new AABB(initialAABB.LowerBoundary.Lerp(targetAABB.LowerBoundary, t), initialAABB.UpperBoundary.Lerp(targetAABB.UpperBoundary, t))));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenCamera2DExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenZoom(this ICamera2D camera2D, ITweenManager tweenManager, float duration, float targetZoom)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        float initialZoom = camera2D.Zoom;
 | 
				
			||||||
 | 
					        return tweenManager.StartTween(duration, t => camera2D.Zoom = initialZoom.Lerp(targetZoom, t));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenCircleExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenCircle(this Circle initialCircle, ITweenManager tweenManager, float duration, Circle targetCircle, System.Action<Circle> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration,
 | 
				
			||||||
 | 
					            t => setMethod?.InvokeSafe(
 | 
				
			||||||
 | 
					                new Circle(
 | 
				
			||||||
 | 
					                    initialCircle.Center.Lerp(targetCircle.Center, t),
 | 
				
			||||||
 | 
					                    initialCircle.Diameter.Lerp(targetCircle.Diameter, t)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenColorExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenColor(this ColorRGB initialColorRGB, ITweenManager tweenManager, float duration, ColorRGB targetColorRGB, System.Action<ColorRGB> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGB.Lerp(targetColorRGB, t)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static ITween TweenColor(this ColorRGBA initialColorRGBA, ITweenManager tweenManager, float duration, ColorRGBA targetColorRGBA, System.Action<ColorRGBA> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGBA.Lerp(targetColorRGBA, t)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static ITween TweenColor(this ColorHSV initialColorHSV, ITweenManager tweenManager, float duration, ColorHSV targetColorHSV, System.Action<ColorHSV> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorHSV.Lerp(targetColorHSV, t)));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenLine2DEquationExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenLine2DEquation(this Line2DEquation initialLine2DEquation, ITweenManager tweenManager, float duration, Line2DEquation targetLine2DEquation, System.Action<Line2DEquation> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration,
 | 
				
			||||||
 | 
					            t => setMethod?.InvokeSafe(
 | 
				
			||||||
 | 
					                new Line2DEquation(
 | 
				
			||||||
 | 
					                    initialLine2DEquation.Slope.Lerp(targetLine2DEquation.Slope, t),
 | 
				
			||||||
 | 
					                    initialLine2DEquation.OffsetY.Lerp(targetLine2DEquation.OffsetY, t)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenLine2DExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenLine2D(this Line2D initialLine2D, ITweenManager tweenManager, float duration, Line2D targetLine2D, System.Action<Line2D> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration,
 | 
				
			||||||
 | 
					            t => setMethod?.InvokeSafe(
 | 
				
			||||||
 | 
					                new Line2D(
 | 
				
			||||||
 | 
					                    initialLine2D.From.Lerp(targetLine2D.From, t),
 | 
				
			||||||
 | 
					                    initialLine2D.To.Lerp(targetLine2D.To, t)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenProjection1DExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenProjection1D(this Projection1D initialProjection1D, ITweenManager tweenManager, float duration, Projection1D targetProjection1D, Action<Projection1D> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration,
 | 
				
			||||||
 | 
					            t => setMethod?.InvokeSafe(
 | 
				
			||||||
 | 
					                new Projection1D(
 | 
				
			||||||
 | 
					                    initialProjection1D.Min.Lerp(targetProjection1D.Min, t),
 | 
				
			||||||
 | 
					                    initialProjection1D.Max.Lerp(targetProjection1D.Max, t)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenQuaternionExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenQuaternion(this Quaternion initialQuaternion, ITweenManager tweenManager, float duration, Quaternion targetQuaternion, Action<Quaternion> setMethod)
 | 
				
			||||||
 | 
					       => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialQuaternion.SLerp(targetQuaternion, t)));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenShape2DExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenShape2D(this Shape2D shape, ITweenManager tweenManager, float duration, Shape2D targetShape2D)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        List<Vector2D> initialVertices = new(shape.Vertices);
 | 
				
			||||||
 | 
					        List<Vector2D> shapeVertices = new(shape.Vertices);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return tweenManager.StartTween(duration,
 | 
				
			||||||
 | 
					                t =>
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    shapeVertices.Clear();
 | 
				
			||||||
 | 
					                    int count = Math.Lerp(initialVertices.Count, targetShape2D.Vertices.Count, t).RoundToInt();
 | 
				
			||||||
 | 
					                    for (int i = 0; i < count; i++)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        int initialIndex = i.Min(initialVertices.Count);
 | 
				
			||||||
 | 
					                        int targetIndex = i.Min(targetShape2D.Vertices.Count);
 | 
				
			||||||
 | 
					                        shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t));
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    shape.Vertices = shapeVertices;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					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));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenTriangleExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenTriangle(this Triangle initialTriangle, ITweenManager tweenManager, float duration, Triangle targetTriangle, Action<Triangle> setMethod)
 | 
				
			||||||
 | 
					       => tweenManager.StartTween(duration,
 | 
				
			||||||
 | 
					            t => setMethod?.InvokeSafe(
 | 
				
			||||||
 | 
					                new Triangle(
 | 
				
			||||||
 | 
					                    initialTriangle.A.Lerp(targetTriangle.A, t),
 | 
				
			||||||
 | 
					                    initialTriangle.B.Lerp(targetTriangle.B, t),
 | 
				
			||||||
 | 
					                    initialTriangle.C.Lerp(targetTriangle.C, t)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenVector2DExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenVector2D(this Vector2D initialVector2D, ITweenManager tweenManager, float duration, Vector2D targetVector2D, System.Action<Vector2D> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector2D.Lerp(targetVector2D, t)));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					using Syntriax.Engine.Core;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Syntriax.Engine.Systems.Tween;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public static class TweenVector3DExtensions
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public static ITween TweenVector3D(this Vector3D initialVector3D, ITweenManager tweenManager, float duration, Vector3D targetVector3D, System.Action<Vector3D> setMethod)
 | 
				
			||||||
 | 
					        => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector3D.Lerp(targetVector3D, t)));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user