1
0
mirror of https://github.com/Cardidi/dotween-upm-fork.git synced 2025-12-20 17:26:03 +08:00

Small fix on string rich text tweens

This commit is contained in:
Daniele Giardini 2015-03-29 16:56:41 +02:00
parent c4e3df3088
commit ebb076e47f
10 changed files with 23 additions and 6 deletions

View File

@ -21,7 +21,7 @@ namespace DG.Tweening
public class DOTween public class DOTween
{ {
/// <summary>DOTween's version</summary> /// <summary>DOTween's version</summary>
public static readonly string Version = "1.0.410"; public static readonly string Version = "1.0.412";
/////////////////////////////////////////////// ///////////////////////////////////////////////
// Options //////////////////////////////////// // Options ////////////////////////////////////

View File

@ -5,12 +5,14 @@
// This work is subject to the terms at http://dotween.demigiant.com/license.php // This work is subject to the terms at http://dotween.demigiant.com/license.php
using System; using System;
using System.Collections.Generic;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using DG.Tweening.Core; 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
@ -20,6 +22,7 @@ namespace DG.Tweening.Plugins
public class StringPlugin : ABSTweenPlugin<string, string, StringOptions> public class StringPlugin : ABSTweenPlugin<string, string, StringOptions>
{ {
static readonly StringBuilder _Buffer = new StringBuilder(); static readonly StringBuilder _Buffer = new StringBuilder();
static readonly List<Char> _OpenedTags = new List<char>(); // Opened tags that need to be closed at the end, stored by first character required in closing tag
public override void SetFrom(TweenerCore<string, string, StringOptions> t, bool isRelative) public override void SetFrom(TweenerCore<string, string, StringOptions> t, bool isRelative)
{ {
@ -118,6 +121,7 @@ namespace DG.Tweening.Plugins
return _Buffer; return _Buffer;
} }
_OpenedTags.Clear();
const string tagMatch = @"<.*?(>)"; const string tagMatch = @"<.*?(>)";
const string closeTagMatch = @"(</).*?>"; const string closeTagMatch = @"(</).*?>";
bool hasOpenTag = false; bool hasOpenTag = false;
@ -127,7 +131,10 @@ namespace DG.Tweening.Plugins
Char c = value[i]; Char c = value[i];
if (c == '<') { if (c == '<') {
bool hadOpenTag = hasOpenTag; bool hadOpenTag = hasOpenTag;
hasOpenTag = !(i < fullLen - 1 && value[i + 1] == '/'); char nextChar = value[i + 1];
hasOpenTag = !(i < fullLen - 1 && nextChar == '/');
if (hasOpenTag) _OpenedTags .Add(nextChar == '#' ? 'c' : nextChar);
else _OpenedTags.RemoveAt(_OpenedTags.Count - 1);
string s = value.Substring(i); string s = value.Substring(i);
Match m = Regex.Match(s, tagMatch); Match m = Regex.Match(s, tagMatch);
if (m.Success) { if (m.Success) {
@ -156,10 +163,20 @@ namespace DG.Tweening.Plugins
} else if (i >= startIndex) _Buffer.Append(c); } else if (i >= startIndex) _Buffer.Append(c);
} }
if (hasOpenTag && i < fullLen - 1) { if (hasOpenTag && i < fullLen - 1) {
string next;
while (_OpenedTags.Count > 0 && i < fullLen - 1) {
// Last open tag was not closed: find next close tag and apply it // Last open tag was not closed: find next close tag and apply it
string next = value.Substring(i); next = value.Substring(i);
Match m = Regex.Match(next, closeTagMatch); Match m = Regex.Match(next, closeTagMatch);
if (m.Success) _Buffer.Append(m.Value); if (m.Success) {
// Append only if it's the correct closing tag
if (m.Value[2] == _OpenedTags[_OpenedTags.Count - 1]) {
_Buffer.Append(m.Value);
_OpenedTags.RemoveAt(_OpenedTags.Count - 1);
}
i += m.Value.Length;
} else break;
}
} }
return _Buffer; return _Buffer;
} }

Binary file not shown.