123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using UnityEngine;
- namespace DG.Tweening
- {
-
-
-
- public static class ShortcutExtensionsTk2d
- {
- #region Sprite
-
-
-
- public static Tweener DOScale(this tk2dBaseSprite target, Vector3 endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, endValue, duration)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleX(this tk2dBaseSprite target, float endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, new Vector3(endValue, 0, 0), duration)
- .SetOptions(AxisConstraint.X)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleY(this tk2dBaseSprite target, float endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, new Vector3(0, endValue, 0), duration)
- .SetOptions(AxisConstraint.Y)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleZ(this tk2dBaseSprite target, float endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, new Vector3(0, 0, endValue), duration)
- .SetOptions(AxisConstraint.Z)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOColor(this tk2dBaseSprite target, Color endValue, float duration)
- {
- return DOTween.To(() => target.color, x => target.color = x, endValue, duration)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOFade(this tk2dBaseSprite target, float endValue, float duration)
- {
- return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration)
- .SetTarget(target);
- }
-
-
-
-
- public static Sequence DOGradientColor(this tk2dBaseSprite target, Gradient gradient, float duration)
- {
- Sequence s = DOTween.Sequence();
- GradientColorKey[] colors = gradient.colorKeys;
- int len = colors.Length;
- for (int i = 0; i < len; ++i) {
- GradientColorKey c = colors[i];
- if (i == 0 && c.time <= 0) {
- target.color = c.color;
- continue;
- }
- float colorDuration = i == len - 1
- ? duration - s.Duration(false)
- : duration * (i == 0 ? c.time : c.time - colors[i - 1].time);
- s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear));
- }
- return s;
- }
- #endregion
- #region tk2dSlicedSprite
-
-
-
- public static Tweener DOScaleDimensions(this tk2dSlicedSprite target, Vector2 endValue, float duration)
- {
- return DOTween.To(() => target.dimensions, x => target.dimensions = x, endValue, duration)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleDimensionsX(this tk2dSlicedSprite target, float endValue, float duration)
- {
- return DOTween.To(() => target.dimensions, x => target.dimensions = x, new Vector2(endValue, 0), duration)
- .SetOptions(AxisConstraint.X)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleDimensionsY(this tk2dSlicedSprite target, float endValue, float duration)
- {
- return DOTween.To(() => target.dimensions, x => target.dimensions = x, new Vector2(0, endValue), duration)
- .SetOptions(AxisConstraint.Y)
- .SetTarget(target);
- }
- #endregion
- #region TextMesh
-
-
-
- public static Tweener DOScale(this tk2dTextMesh target, Vector3 endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, endValue, duration)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleX(this tk2dTextMesh target, float endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, new Vector3(endValue, 0, 0), duration)
- .SetOptions(AxisConstraint.X)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleY(this tk2dTextMesh target, float endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, new Vector3(0, endValue, 0), duration)
- .SetOptions(AxisConstraint.Y)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOScaleZ(this tk2dTextMesh target, float endValue, float duration)
- {
- return DOTween.To(() => target.scale, x => target.scale = x, new Vector3(0, 0, endValue), duration)
- .SetOptions(AxisConstraint.Z)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOColor(this tk2dTextMesh target, Color endValue, float duration)
- {
- return DOTween.To(() => target.color, x => target.color = x, endValue, duration)
- .SetTarget(target);
- }
-
-
-
- public static Tweener DOFade(this tk2dTextMesh target, float endValue, float duration)
- {
- return DOTween.ToAlpha(() => target.color, x => target.color = x, endValue, duration)
- .SetTarget(target);
- }
-
-
-
-
- public static Sequence DOGradientColor(this tk2dTextMesh target, Gradient gradient, float duration)
- {
- Sequence s = DOTween.Sequence();
- GradientColorKey[] colors = gradient.colorKeys;
- int len = colors.Length;
- for (int i = 0; i < len; ++i) {
- GradientColorKey c = colors[i];
- if (i == 0 && c.time <= 0) {
- target.color = c.color;
- continue;
- }
- float colorDuration = i == len - 1
- ? duration - s.Duration(false)
- : duration * (i == 0 ? c.time : c.time - colors[i - 1].time);
- s.Append(target.DOColor(c.color, colorDuration).SetEase(Ease.Linear));
- }
- return s;
- }
-
-
-
-
-
-
-
-
-
- public static Tweener DOText(this tk2dTextMesh target, string endValue, float duration, bool richTextEnabled = true, ScrambleMode scrambleMode = ScrambleMode.None, string scrambleChars = null)
- {
- return DOTween.To(() => target.text, x => target.text = x, endValue, duration)
- .SetOptions(richTextEnabled, scrambleMode, scrambleChars)
- .SetTarget(target);
- }
- #endregion
- }
- }
|