Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion Runtime/Scripts/Extensions/DashTweenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}
}