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
116 changes: 115 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,119 @@ 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;
}

public static DashTween DashAnchoredPositionX(this RectTransform p_rectTransform,
float p_finalPosition,
float p_duration,
EaseType p_easeType = EaseType.LINEAR,
float p_delay = 0f)
{
var posY = p_rectTransform.anchoredPosition.y;
return p_rectTransform.TEST_DashAnchoredPosition(new Vector2(p_finalPosition, posY),
p_duration,
p_easeType,
p_delay);
}

public static DashTween DashAnchoredPositionY(this RectTransform p_rectTransform,
float p_finalPosition,
float p_duration,
EaseType p_easeType = EaseType.LINEAR,
float p_delay = 0f)
{
var posX = p_rectTransform.anchoredPosition.x;
return p_rectTransform.TEST_DashAnchoredPosition(new Vector2(posX, p_finalPosition),
p_duration,
p_easeType,
p_delay);
}

public static DashTween DashSizeDelta(this RectTransform p_rectTransform,
Vector2 p_finalSize,
float p_duration,
EaseType p_easeType = EaseType.LINEAR,
float p_delay = 0f)
{
var original = p_rectTransform.sizeDelta;
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.sizeDelta = new Vector2(
DashTween.EaseValue(original.x, p_finalSize.x, delta, p_easeType),
DashTween.EaseValue(original.y, p_finalSize.y, delta, p_easeType));
});
tween.Start();
return tween;
}

public static DashTween DashScale(this RectTransform p_rectTransform,
Vector2 p_finalScale,
float p_duration,
EaseType p_easeType = EaseType.LINEAR,
float p_delay = 0f)
{
var original = p_rectTransform.localScale;
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.localScale = new Vector3(
DashTween.EaseValue(original.x, p_finalScale.x, delta, p_easeType),
DashTween.EaseValue(original.y, p_finalScale.y, delta, p_easeType),
1f);
});
tween.Start();
return tween;
}
}
}