TextPic.cs Added Fix for href tag, which was not working. Added support for multiple href tag with same name.
--HG-- branch : sushanta1991/textpiccs-was-not-working-for-href-unit-1474979920532release
parent
b75a03963e
commit
18cf84b4d0
|
@ -81,6 +81,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
//private bool selected = false;
|
//private bool selected = false;
|
||||||
|
|
||||||
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,
|
||||||
|
@ -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,58 +310,42 @@ 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];
|
||||||
int foundAtIndex = -1;
|
if(isCreating_m_HrefInfos) {
|
||||||
// checking if m_HrefInfos element with same name already exists than just updating it with new values, instead of recreating it without bound data (which is important for href tag)
|
var hrefInfo = new HrefInfo
|
||||||
if(HrefInfosDoesExists(group.Value,out foundAtIndex)) {
|
{
|
||||||
m_HrefInfos[foundAtIndex].startIndex = s_TextBuilder.Length * 4; // Hyperlinks in text starting vertex indices;
|
startIndex = s_TextBuilder.Length * 4, // Hyperlinks in text starting vertex indices
|
||||||
m_HrefInfos[foundAtIndex].endIndex = (s_TextBuilder.Length + match.Groups[2].Length - 1) * 4 + 3;
|
endIndex = (s_TextBuilder.Length + match.Groups[2].Length - 1) * 4 + 3,
|
||||||
} else {
|
name = group.Value
|
||||||
var hrefInfo = new HrefInfo
|
};
|
||||||
{
|
m_HrefInfos.Add(hrefInfo);
|
||||||
startIndex = s_TextBuilder.Length * 4, // Hyperlinks in text starting vertex indices
|
} else {
|
||||||
endIndex = (s_TextBuilder.Length + match.Groups[2].Length - 1) * 4 + 3,
|
if(m_HrefInfos.Count > 0) {
|
||||||
name = group.Value
|
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;
|
||||||
m_HrefInfos.Add(hrefInfo);
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If Href exists than just modify its startIndex and endIndex, dont clear the whole array of m_HrefInfos which also clears the previously created boxes for href.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns><c>true</c>, if hrefName already exists in the list of m_HrefInfos, <c>false</c> otherwise.</returns>
|
|
||||||
/// <param name="hrefName">Href name.</param>
|
|
||||||
/// <param name="indexAt">Index at.</param>
|
|
||||||
private bool HrefInfosDoesExists(string hrefName, out int indexAt) {
|
|
||||||
bool flag = false;
|
|
||||||
int foundAtIndex = -1;
|
|
||||||
foreach(var hrefInfoTest in m_HrefInfos){
|
|
||||||
if(hrefInfoTest.name == hrefName) {
|
|
||||||
foundAtIndex++;
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
foundAtIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
indexAt = foundAtIndex;
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Click event is detected whether to click a hyperlink text
|
/// Click event is detected whether to click a hyperlink text
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -454,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