1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2026-02-04 22:34:56 +08:00

Rich text support (including well formed nested tags) for string tweens fully implemented

This commit is contained in:
Daniele Giardini 2015-03-29 13:44:58 +02:00
parent c9c985041d
commit c4e3df3088
49 changed files with 162 additions and 71 deletions

View File

@ -567,9 +567,11 @@
<summary>Options for Vector4 tweens</summary> <summary>Options for Vector4 tweens</summary>
<param name="snapping">If TRUE the tween will smoothly snap all values to integers</param> <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
</member> </member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{System.String,System.String,DG.Tweening.Plugins.Options.StringOptions},System.Boolean,System.String)"> <member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{System.String,System.String,DG.Tweening.Plugins.Options.StringOptions},System.Boolean,DG.Tweening.ScrambleMode,System.String)">
<summary>Options for Vector4 tweens</summary> <summary>Options for Vector4 tweens</summary>
<param name="scramble">If TRUE the string will appear from a random animation of characters</param> <param name="richTextEnabled">If TRUE, rich text will be interpreted correctly while animated,
otherwise all tags will be considered as normal text</param>
<param name="scrambleMode">The type of scramble to use, if any</param>
<param name="scrambleChars">A string containing the characters to use for scrambling. <param name="scrambleChars">A string containing the characters to use for scrambling.
Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
Leave it to NULL to use default ones</param> Leave it to NULL to use default ones</param>
@ -1904,6 +1906,41 @@
What axis to constrain in case of Vector tweens What axis to constrain in case of Vector tweens
</summary> </summary>
</member> </member>
<member name="T:DG.Tweening.ScrambleMode">
<summary>
Type of scramble to apply to string tweens
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.None">
<summary>
No scrambling of characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.All">
<summary>
A-Z + a-z + 0-9 characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Uppercase">
<summary>
A-Z characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Lowercase">
<summary>
a-z characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Numerals">
<summary>
0-9 characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Custom">
<summary>
Custom characters
</summary>
</member>
<member name="T:DG.Tweening.Plugins.Core.PathCore.ControlPoint"> <member name="T:DG.Tweening.Plugins.Core.PathCore.ControlPoint">
<summary> <summary>
Path control point Path control point

View File

@ -107,11 +107,13 @@
Also stores the Text as the tween's target so it can be used for filtered operations</summary> Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param> <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
</member> </member>
<member name="M:DG.Tweening.ShortcutExtensions.DOText(UnityEngine.UI.Text,System.String,System.Single,System.Boolean,System.String)"> <member name="M:DG.Tweening.ShortcutExtensions.DOText(UnityEngine.UI.Text,System.String,System.Single,System.Boolean,DG.Tweening.ScrambleMode,System.String)">
<summary>Tweens a Text's text to the given value. <summary>Tweens a Text's text to the given value.
Also stores the Text as the tween's target so it can be used for filtered operations</summary> Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param> <param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param>
<param name="scramble">If TRUE the string will appear from a random animation of characters</param> <param name="richTextEnabled">If TRUE (default), rich text will be interpreted correctly while animated,
otherwise all tags will be considered as normal text</param>
<param name="scrambleMode">The type of scramble mode to use, if any</param>
<param name="scrambleChars">A string containing the characters to use for scrambling. <param name="scrambleChars">A string containing the characters to use for scrambling.
Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
Leave it to NULL (default) to use default ones</param> Leave it to NULL (default) to use default ones</param>

View File

@ -567,9 +567,11 @@
<summary>Options for Vector4 tweens</summary> <summary>Options for Vector4 tweens</summary>
<param name="snapping">If TRUE the tween will smoothly snap all values to integers</param> <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
</member> </member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{System.String,System.String,DG.Tweening.Plugins.Options.StringOptions},System.Boolean,System.String)"> <member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{System.String,System.String,DG.Tweening.Plugins.Options.StringOptions},System.Boolean,DG.Tweening.ScrambleMode,System.String)">
<summary>Options for Vector4 tweens</summary> <summary>Options for Vector4 tweens</summary>
<param name="scramble">If TRUE the string will appear from a random animation of characters</param> <param name="richTextEnabled">If TRUE, rich text will be interpreted correctly while animated,
otherwise all tags will be considered as normal text</param>
<param name="scrambleMode">The type of scramble to use, if any</param>
<param name="scrambleChars">A string containing the characters to use for scrambling. <param name="scrambleChars">A string containing the characters to use for scrambling.
Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
Leave it to NULL to use default ones</param> Leave it to NULL to use default ones</param>
@ -1904,6 +1906,41 @@
What axis to constrain in case of Vector tweens What axis to constrain in case of Vector tweens
</summary> </summary>
</member> </member>
<member name="T:DG.Tweening.ScrambleMode">
<summary>
Type of scramble to apply to string tweens
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.None">
<summary>
No scrambling of characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.All">
<summary>
A-Z + a-z + 0-9 characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Uppercase">
<summary>
A-Z characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Lowercase">
<summary>
a-z characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Numerals">
<summary>
0-9 characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Custom">
<summary>
Custom characters
</summary>
</member>
<member name="T:DG.Tweening.Plugins.Core.PathCore.ControlPoint"> <member name="T:DG.Tweening.Plugins.Core.PathCore.ControlPoint">
<summary> <summary>
Path control point Path control point

View File

@ -107,11 +107,13 @@
Also stores the Text as the tween's target so it can be used for filtered operations</summary> Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param> <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
</member> </member>
<member name="M:DG.Tweening.ShortcutExtensions.DOText(UnityEngine.UI.Text,System.String,System.Single,System.Boolean,System.String)"> <member name="M:DG.Tweening.ShortcutExtensions.DOText(UnityEngine.UI.Text,System.String,System.Single,System.Boolean,DG.Tweening.ScrambleMode,System.String)">
<summary>Tweens a Text's text to the given value. <summary>Tweens a Text's text to the given value.
Also stores the Text as the tween's target so it can be used for filtered operations</summary> Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param> <param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param>
<param name="scramble">If TRUE the string will appear from a random animation of characters</param> <param name="richTextEnabled">If TRUE (default), rich text will be interpreted correctly while animated,
otherwise all tags will be considered as normal text</param>
<param name="scrambleMode">The type of scramble mode to use, if any</param>
<param name="scrambleChars">A string containing the characters to use for scrambling. <param name="scrambleChars">A string containing the characters to use for scrambling.
Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
Leave it to NULL (default) to use default ones</param> Leave it to NULL (default) to use default ones</param>

View File

@ -567,9 +567,11 @@
<summary>Options for Vector4 tweens</summary> <summary>Options for Vector4 tweens</summary>
<param name="snapping">If TRUE the tween will smoothly snap all values to integers</param> <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
</member> </member>
<member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{System.String,System.String,DG.Tweening.Plugins.Options.StringOptions},System.Boolean,System.String)"> <member name="M:DG.Tweening.TweenSettingsExtensions.SetOptions(DG.Tweening.Core.TweenerCore{System.String,System.String,DG.Tweening.Plugins.Options.StringOptions},System.Boolean,DG.Tweening.ScrambleMode,System.String)">
<summary>Options for Vector4 tweens</summary> <summary>Options for Vector4 tweens</summary>
<param name="scramble">If TRUE the string will appear from a random animation of characters</param> <param name="richTextEnabled">If TRUE, rich text will be interpreted correctly while animated,
otherwise all tags will be considered as normal text</param>
<param name="scrambleMode">The type of scramble to use, if any</param>
<param name="scrambleChars">A string containing the characters to use for scrambling. <param name="scrambleChars">A string containing the characters to use for scrambling.
Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
Leave it to NULL to use default ones</param> Leave it to NULL to use default ones</param>
@ -1904,6 +1906,41 @@
What axis to constrain in case of Vector tweens What axis to constrain in case of Vector tweens
</summary> </summary>
</member> </member>
<member name="T:DG.Tweening.ScrambleMode">
<summary>
Type of scramble to apply to string tweens
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.None">
<summary>
No scrambling of characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.All">
<summary>
A-Z + a-z + 0-9 characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Uppercase">
<summary>
A-Z characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Lowercase">
<summary>
a-z characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Numerals">
<summary>
0-9 characters
</summary>
</member>
<member name="F:DG.Tweening.ScrambleMode.Custom">
<summary>
Custom characters
</summary>
</member>
<member name="T:DG.Tweening.Plugins.Core.PathCore.ControlPoint"> <member name="T:DG.Tweening.Plugins.Core.PathCore.ControlPoint">
<summary> <summary>
Path control point Path control point

View File

@ -107,11 +107,13 @@
Also stores the Text as the tween's target so it can be used for filtered operations</summary> Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param> <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param>
</member> </member>
<member name="M:DG.Tweening.ShortcutExtensions.DOText(UnityEngine.UI.Text,System.String,System.Single,System.Boolean,System.String)"> <member name="M:DG.Tweening.ShortcutExtensions.DOText(UnityEngine.UI.Text,System.String,System.Single,System.Boolean,DG.Tweening.ScrambleMode,System.String)">
<summary>Tweens a Text's text to the given value. <summary>Tweens a Text's text to the given value.
Also stores the Text as the tween's target so it can be used for filtered operations</summary> Also stores the Text as the tween's target so it can be used for filtered operations</summary>
<param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param> <param name="endValue">The end string to tween to</param><param name="duration">The duration of the tween</param>
<param name="scramble">If TRUE the string will appear from a random animation of characters</param> <param name="richTextEnabled">If TRUE (default), rich text will be interpreted correctly while animated,
otherwise all tags will be considered as normal text</param>
<param name="scrambleMode">The type of scramble mode to use, if any</param>
<param name="scrambleChars">A string containing the characters to use for scrambling. <param name="scrambleChars">A string containing the characters to use for scrambling.
Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters. Use as many characters as possible (minimum 10) because DOTween uses a fast scramble mode which gives better results with more characters.
Leave it to NULL (default) to use default ones</param> Leave it to NULL (default) to use default ones</param>

View File

@ -7,24 +7,46 @@ public class ExternalPlugins_TextMeshPro : BrainBase
{ {
public TextMeshPro[] texts; public TextMeshPro[] texts;
const string ReplaceText = "This text is gonna appear with a tween, yabadabadoo!"; [TextArea(5, 10)]
public string replaceWText = "This <#00ff00>rich <b>bold</b>+<i>italic</i> text</color> is <#ff0000>gonna appear</color> with a tween, <#f38013>yabadabadoo!</color>";
bool richTextEnabled = true;
string[] orTexts;
void Start() void Start()
{ {
DOTween.Init(); DOTween.Init();
orTexts = new string[texts.Length];
for (int i = 0; i < texts.Length; ++i) orTexts[i] = texts[i].text;
} }
void OnGUI() void OnGUI()
{ {
GUILayout.Label("These tweens won't stack. Run one at a time"); if (GUILayout.Button("Rich Text Support: " + (richTextEnabled ? "ON" : "OFF"))) richTextEnabled = !richTextEnabled;
GUILayout.BeginHorizontal();
if (GUILayout.Button("Color To Green")) foreach (TextMeshPro t in texts) t.DOColor(Color.green, 1).SetEase(Ease.Linear); if (GUILayout.Button("Color To Green")) foreach (TextMeshPro t in texts) t.DOColor(Color.green, 1).SetEase(Ease.Linear);
if (GUILayout.Button("Color To Red")) foreach (TextMeshPro t in texts) t.DOColor(Color.red, 1).SetEase(Ease.Linear); if (GUILayout.Button("Color To Red")) foreach (TextMeshPro t in texts) t.DOColor(Color.red, 1).SetEase(Ease.Linear);
if (GUILayout.Button("Fade Out")) foreach (TextMeshPro t in texts) t.DOFade(0, 1).SetEase(Ease.Linear); if (GUILayout.Button("Fade Out")) foreach (TextMeshPro t in texts) t.DOFade(0, 1).SetEase(Ease.Linear);
if (GUILayout.Button("Fade In")) foreach (TextMeshPro t in texts) t.DOFade(1, 1).SetEase(Ease.Linear); if (GUILayout.Button("Fade In")) foreach (TextMeshPro t in texts) t.DOFade(1, 1).SetEase(Ease.Linear);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Font Resize Down")) foreach (TextMeshPro t in texts) t.DOFontSize(10, 1); if (GUILayout.Button("Font Resize Down")) foreach (TextMeshPro t in texts) t.DOFontSize(10, 1);
if (GUILayout.Button("Font Resize Up")) foreach (TextMeshPro t in texts) t.DOFontSize(32, 1); if (GUILayout.Button("Font Resize Up")) foreach (TextMeshPro t in texts) t.DOFontSize(32, 1);
if (GUILayout.Button("Trim Max Visible Characters")) foreach (TextMeshPro t in texts) t.DOMaxVisibleCharacters(22, 1); if (GUILayout.Button("Trim Max Visible Characters")) foreach (TextMeshPro t in texts) t.DOMaxVisibleCharacters(22, 1);
if (GUILayout.Button("Text Replace")) foreach (TextMeshPro t in texts) t.DOText(ReplaceText, 2).SetEase(Ease.Linear); GUILayout.EndHorizontal();
if (GUILayout.Button("Text Replace W Scramble")) foreach (TextMeshPro t in texts) t.DOText(ReplaceText, 2, true).SetEase(Ease.Linear); GUILayout.BeginHorizontal();
if (GUILayout.Button("Text Reset")) {
DOTween.KillAll();
for (int i = 0; i < texts.Length; ++i) texts[i].text = orTexts[i];
}
if (GUILayout.Button("Text Replace")) foreach (TextMeshPro t in texts) t.DOText(replaceWText, 5, richTextEnabled).SetEase(Ease.Linear);
if (GUILayout.Button("Text Replace Add")) foreach (TextMeshPro t in texts) t.DOText(" " + replaceWText, 5, richTextEnabled).SetRelative().SetEase(Ease.Linear);
if (GUILayout.Button("Text Replace W Scramble")) foreach (TextMeshPro t in texts) t.DOText(replaceWText, 5, richTextEnabled, ScrambleMode.Lowercase).SetEase(Ease.Linear);
if (GUILayout.Button("Text Replace Add W Scramble")) foreach (TextMeshPro t in texts) t.DOText(" " + replaceWText, 5, richTextEnabled, ScrambleMode.Lowercase).SetRelative().SetEase(Ease.Linear);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("TogglePause")) DOTween.TogglePauseAll();
if (GUILayout.Button("Flip")) DOTween.FlipAll();
GUILayout.EndHorizontal();
} }
} }

View File

@ -11,7 +11,6 @@ using DG.Tweening.Core;
using DG.Tweening.Core.Easing; using DG.Tweening.Core.Easing;
using DG.Tweening.Plugins.Core; using DG.Tweening.Plugins.Core;
using DG.Tweening.Plugins.Options; using DG.Tweening.Plugins.Options;
using UnityEngine;
using Random = UnityEngine.Random; using Random = UnityEngine.Random;
#pragma warning disable 1591 #pragma warning disable 1591
@ -95,7 +94,6 @@ namespace DG.Tweening.Plugins
} }
if (options.scrambleMode != ScrambleMode.None) { if (options.scrambleMode != ScrambleMode.None) {
// setter(_Buffer.Append(changeValue, 0, len).AppendScrambledChars(changeValueLen - len, ScrambledCharsToUse(options)).ToString());
setter(Append(changeValue, 0, len, options.richTextEnabled).AppendScrambledChars(changeValueLen - len, ScrambledCharsToUse(options)).ToString()); setter(Append(changeValue, 0, len, options.richTextEnabled).AppendScrambledChars(changeValueLen - len, ScrambledCharsToUse(options)).ToString());
return; return;
} }
@ -134,10 +132,14 @@ namespace DG.Tweening.Plugins
Match m = Regex.Match(s, tagMatch); Match m = Regex.Match(s, tagMatch);
if (m.Success) { if (m.Success) {
if (!hasOpenTag && !hadOpenTag) { if (!hasOpenTag && !hadOpenTag) {
// We have a closing tag without an opening tag, try to find opening tag an apply it // We have a closing tag without an opening tag, try to find previous correct opening tag an apply it
char closingTagFirstChar = value[i + 1];
char[] openingTagLookouts;
if (closingTagFirstChar == 'c') openingTagLookouts = new[] { '#', 'c' };
else openingTagLookouts = new[] { closingTagFirstChar };
int t = i - 1; int t = i - 1;
while (t > -1) { while (t > -1) {
if (value[t] == '<' && value[t + 1] != '/') { if (value[t] == '<' && value[t + 1] != '/' && Array.IndexOf(openingTagLookouts, value[t + 2]) != -1) {
_Buffer.Insert(0, value.Substring(t, value.IndexOf('>', t) + 1 - t)); _Buffer.Insert(0, value.Substring(t, value.IndexOf('>', t) + 1 - t));
break; break;
} }
@ -177,56 +179,6 @@ namespace DG.Tweening.Plugins
return StringPluginExtensions.ScrambledCharsAll; return StringPluginExtensions.ScrambledCharsAll;
} }
} }
// public override void EvaluateAndApply(StringOptions options, Tween t, bool isRelative, DOGetter<string> getter, DOSetter<string> setter, float elapsed, string startValue, string changeValue, float duration, bool usingInversePosition)
// {
// _Buffer.Remove(0, _Buffer.Length);
//
// // Incremental works only with relative tweens (otherwise the tween makes no sense)
// // Sequence with Incremental loops have no effect here (why should they?)
// if (isRelative && t.loopType == LoopType.Incremental) {
// int iterations = t.isComplete ? t.completedLoops - 1 : t.completedLoops;
// if (iterations > 0) {
// _Buffer.Append(startValue);
// for (int i = 0; i < iterations; ++i) _Buffer.Append(changeValue);
// startValue = _Buffer.ToString();
// _Buffer.Remove(0, _Buffer.Length);
// }
// }
//
// int startValueLen = startValue.Length;
// int changeValueLen = changeValue.Length;
// int len = (int)Math.Round(changeValueLen * EaseManager.Evaluate(t.easeType, t.customEase, elapsed, duration, t.easeOvershootOrAmplitude, t.easePeriod));
// if (len > changeValueLen) len = changeValueLen;
// else if (len < 0) len = 0;
//
// if (isRelative) {
// _Buffer.Append(startValue);
// if (options.scramble) {
// setter(_Buffer.Append(changeValue, 0, len).AppendScrambledChars(changeValueLen - len, options.scrambledChars ?? StringPluginExtensions.ScrambledChars).ToString());
// return;
// }
// setter(_Buffer.Append(changeValue, 0, len).ToString());
// return;
// }
//
// if (options.scramble) {
// setter(_Buffer.Append(changeValue, 0, len).AppendScrambledChars(changeValueLen - len, options.scrambledChars ?? StringPluginExtensions.ScrambledChars).ToString());
// return;
// }
//
// int diff = startValueLen - changeValueLen;
// int startValueMaxLen = startValueLen;
// if (diff > 0) {
// // String to be replaced is longer than endValue: remove parts of it while tweening
// float perc = (float)len / changeValueLen;
// startValueMaxLen -= (int)(startValueMaxLen * perc);
// } else startValueMaxLen -= len;
// _Buffer.Append(changeValue, 0, len);
// if (len < changeValueLen && len < startValueLen) _Buffer.Append(startValue, len, startValueMaxLen);
// setter(_Buffer.ToString());
// }
} }
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.