diff --git a/Runtime/Scripts/Extensions/DashTweenExtensions.cs b/Runtime/Scripts/Extensions/DashTweenExtensions.cs index 03fdcce..ae36df0 100644 --- a/Runtime/Scripts/Extensions/DashTweenExtensions.cs +++ b/Runtime/Scripts/Extensions/DashTweenExtensions.cs @@ -9,7 +9,7 @@ namespace Dash { public static class DashTweenExtensions { - static public bool DoNullChecks = false; + public static bool DoNullChecks = false; public static DashTween DashLocalRotate(this Transform p_transform, Vector3 p_rotation, float p_time, bool p_useSpeed = false) { @@ -86,5 +86,34 @@ public static DashTween DashColor(this Graphic p_graphic, Color p_color, float p }).Start(); return tween; } + + public static DashTween DashAnchoredPosition(this RectTransform p_rectTransform, + Vector2 p_finalPosition, + float p_duration, + EaseType p_easeType = EaseType.LINEAR, + float p_delay = 0f) + { + var original = p_rectTransform.anchoredPosition; + var tween = DashTween.To(p_rectTransform, 0f, 1f, p_duration); + + if (p_delay >= 0f) + { + tween.SetDelay(p_delay); + } + + tween.OnInternalUpdate(delta => + { + if (DoNullChecks && p_rectTransform == null) + { + return; + } + + p_rectTransform.anchoredPosition = new Vector2( + DashTween.EaseValue(original.x, p_finalPosition.x, delta, p_easeType), + DashTween.EaseValue(original.y, p_finalPosition.y, delta, p_easeType)); + }); + tween.Start(); + return tween; + } } } \ No newline at end of file