Merged in sushanta1991/unity-ui-extensions-1/sushanta1991/textpiccs-was-not-working-for-href-unit-1474979920532 (pull request #29)
TextPic.cs Added Fix for href tag which was not working. --HG-- branch : develop_5.3pull/413/head
commit
d890858afb
|
@ -82,6 +82,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
private List<Vector2> positions = new List<Vector2>();
|
private List<Vector2> positions = new List<Vector2>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Little heck to support multiple hrefs with same name
|
||||||
|
*/
|
||||||
|
private string previousText = "";
|
||||||
|
public bool isCreating_m_HrefInfos = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unity Inspector cant display Dictionary vars,
|
* Unity Inspector cant display Dictionary vars,
|
||||||
* so we use this little hack to setup the iconList
|
* so we use this little hack to setup the iconList
|
||||||
|
@ -97,6 +103,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
iconList.Add(icon.name, icon.sprite);
|
iconList.Add(icon.name, icon.sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reset_m_HrefInfos ();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void UpdateQuadImage()
|
protected void UpdateQuadImage()
|
||||||
|
@ -290,7 +297,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
protected string GetOutputText()
|
protected string GetOutputText()
|
||||||
{
|
{
|
||||||
s_TextBuilder.Length = 0;
|
s_TextBuilder.Length = 0;
|
||||||
m_HrefInfos.Clear();
|
|
||||||
var indexText = 0;
|
var indexText = 0;
|
||||||
fixedString = this.text;
|
fixedString = this.text;
|
||||||
if (inspectorIconList != null && inspectorIconList.Length > 0)
|
if (inspectorIconList != null && inspectorIconList.Length > 0)
|
||||||
|
@ -303,24 +310,37 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int count = 0;
|
||||||
foreach (Match match in s_HrefRegex.Matches(fixedString))
|
foreach (Match match in s_HrefRegex.Matches(fixedString))
|
||||||
{
|
{
|
||||||
s_TextBuilder.Append(fixedString.Substring(indexText, match.Index - indexText));
|
s_TextBuilder.Append(fixedString.Substring(indexText, match.Index - indexText));
|
||||||
s_TextBuilder.Append("<color=" + hyperlinkColor + ">"); // Hyperlink color
|
s_TextBuilder.Append("<color=" + hyperlinkColor + ">"); // Hyperlink color
|
||||||
|
|
||||||
var group = match.Groups[1];
|
var group = match.Groups[1];
|
||||||
var hrefInfo = new HrefInfo
|
if(isCreating_m_HrefInfos) {
|
||||||
{
|
var hrefInfo = new HrefInfo
|
||||||
startIndex = s_TextBuilder.Length * 4, // Hyperlinks in text starting vertex indices
|
{
|
||||||
endIndex = (s_TextBuilder.Length + match.Groups[2].Length - 1) * 4 + 3,
|
startIndex = s_TextBuilder.Length * 4, // Hyperlinks in text starting vertex indices
|
||||||
name = group.Value
|
endIndex = (s_TextBuilder.Length + match.Groups[2].Length - 1) * 4 + 3,
|
||||||
};
|
name = group.Value
|
||||||
m_HrefInfos.Add(hrefInfo);
|
};
|
||||||
|
m_HrefInfos.Add(hrefInfo);
|
||||||
|
} else {
|
||||||
|
if(m_HrefInfos.Count > 0) {
|
||||||
|
m_HrefInfos[count].startIndex = s_TextBuilder.Length * 4; // Hyperlinks in text starting vertex indices;
|
||||||
|
m_HrefInfos[count].endIndex = (s_TextBuilder.Length + match.Groups[2].Length - 1) * 4 + 3;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s_TextBuilder.Append(match.Groups[2].Value);
|
s_TextBuilder.Append(match.Groups[2].Value);
|
||||||
s_TextBuilder.Append("</color>");
|
s_TextBuilder.Append("</color>");
|
||||||
indexText = match.Index + match.Length;
|
indexText = match.Index + match.Length;
|
||||||
}
|
}
|
||||||
|
// we should create array only once or if there is any change in the text
|
||||||
|
if(isCreating_m_HrefInfos)
|
||||||
|
isCreating_m_HrefInfos = false;
|
||||||
|
|
||||||
s_TextBuilder.Append(fixedString.Substring(indexText, fixedString.Length - indexText));
|
s_TextBuilder.Append(fixedString.Substring(indexText, fixedString.Length - indexText));
|
||||||
|
|
||||||
return s_TextBuilder.ToString();
|
return s_TextBuilder.ToString();
|
||||||
|
@ -425,6 +445,15 @@ namespace UnityEngine.UI.Extensions
|
||||||
culled_ImagesPool.Clear();
|
culled_ImagesPool.Clear();
|
||||||
clearImages = false;
|
clearImages = false;
|
||||||
}
|
}
|
||||||
|
if( previousText != text)
|
||||||
|
Reset_m_HrefInfos ();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reseting m_HrefInfos array if there is any change in text
|
||||||
|
void Reset_m_HrefInfos () {
|
||||||
|
previousText = text;
|
||||||
|
m_HrefInfos.Clear();
|
||||||
|
isCreating_m_HrefInfos = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue