Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Copyright (c) 2025 Kai Clavier [kaiclavier.com] Do Not Distribute
- //DOTween belongs to DEMIGIANT [dotween.demigiant.com]
- using DG.Tweening;
- using DG.Tweening.Core;
- using DG.Tweening.Plugins.Options;
- using UnityEngine;
- /*
- * superTextMesh.DOFade(endValue, duration);
- * superTextMesh.DOColor(endValue, duration);
- * superTextMesh.DOBlendableColor(endValue, duration);
- * superTextMesh.DORead(duration, drawAnimName (optional), startIndex (optional));
- * superTextMesh.DOSize(endValue, duration);
- */
- namespace Clavian.STM.Extensions
- {
- public static class STMDOTweenExtensions
- {
- public static TweenerCore<float, float, FloatOptions> DOFade(
- this SuperTextMesh target,
- float endValue,
- float duration)
- {
- TweenerCore<float, float, FloatOptions> alpha = DOTween.To(
- (DOGetter<float>)(() => target.fade),
- (DOSetter<float>)(x => target.fade = x),
- endValue,
- duration);
- return alpha;
- }
- public static TweenerCore<Color, Color, ColorOptions> DOColor(
- this SuperTextMesh target,
- Color endValue,
- float duration)
- {
- TweenerCore<Color, Color, ColorOptions> t = DOTween.To(
- (DOGetter<Color>) (() => target.color),
- (DOSetter<Color>) (x => target.color = x),
- endValue,
- duration);
- //turns out, this isn't needed?
- //.OnUpdate(() => target.SetMesh(target.currentReadTime))
- t.SetTarget<TweenerCore<Color, Color, ColorOptions>>((object) target);
- return t;
- }
- public static Tweener DOBlendableColor(
- this SuperTextMesh target,
- Color endValue,
- float duration)
- {
- endValue -= target.color;
- Color to = new Color(0.0f, 0.0f, 0.0f, 0.0f);
- return (Tweener) DOTween.To((DOGetter<Color>) (() => to), (DOSetter<Color>) (x =>
- {
- Color color = x - to;
- to = x;
- target.color += color;
- }), endValue, duration).Blendable<Color, Color, ColorOptions>().SetTarget<TweenerCore<Color, Color, ColorOptions>>((object) target);
- }
- //this does not make sounds or call events vs. calling SuperTextMesh.Read()
- public static TweenerCore<float, float, FloatOptions> DORead(
- this SuperTextMesh target,
- float duration,
- string drawAnimName = "",
- float startIndex = 0f)
- {
- if(target.characterCount == 0) return null;
- if(drawAnimName?.Length > 0) target.drawAnimName = drawAnimName;
- target.readDelay = duration / target.characterCount;
- target.Rebuild(startIndex * target.readDelay, false); //sets current read time...
- TweenerCore<float, float, FloatOptions> read = DOTween.To(
- (DOGetter<float>)(() => target.currentReadTime),
- (DOSetter<float>)(x =>
- {
- target.reading = true;
- target.currentReadTime = x;
- target.SetMesh(target.currentReadTime);
- }),
- duration,
- duration).OnComplete(target.ShowAllText); //sets reading to false
- return read;
- }
- //a bit heavier than the other methods, as Rebuild() is called when the tween updates.
- public static TweenerCore<float, float, FloatOptions> DOSize(
- this SuperTextMesh target,
- float endValue,
- float duration)
- {
- TweenerCore<float, float, FloatOptions> size = DOTween.To(
- (DOGetter<float>)(() => target.size),
- (DOSetter<float>)(x =>
- {
- target.size = x;
- target.Rebuild();
- }),
- endValue,
- duration);
- return size;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment