TextPic.cs was not working for href.
Unity-UI-Extensions helped me a lot thanks for creating it. Today i was trying href tag provided with TextPic.cs, but unfortunately it was not working. I figured out that, OnPopulateMesh() was creating hrefInfo.boxes but at the end when OnPopulateMesh() calls UpdateQuadImage(), hrefInfo.boxes.count was coming 0. This was little strange but i saw that GetOutputText() was re-creating m_HrefInfos array from scratch but it didn't include the code to add boxes, so this was the issue. so what i did is, i commented this line m_HrefInfos.Clear(); in GetOutputText() and added few lines of code to check if m_HrefInfos elements exists than don't destroy it, just update it with new values. This helped in resolving the issue. Now i was getting onClick event on href tag. Thanks --HG-- branch : sushanta1991/textpiccs-was-not-working-for-href-unit-1474979920532release
parent
154c9c8d31
commit
292fb39c93
|
@ -43,13 +43,13 @@ namespace UnityEngine.UI.Extensions
|
||||||
UpdateQuadImage();
|
UpdateQuadImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
protected override void OnValidate()
|
protected override void OnValidate()
|
||||||
{
|
{
|
||||||
base.OnValidate();
|
base.OnValidate();
|
||||||
UpdateQuadImage();
|
UpdateQuadImage();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// After parsing the final text
|
/// After parsing the final text
|
||||||
|
@ -101,12 +101,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
protected void UpdateQuadImage()
|
protected void UpdateQuadImage()
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (UnityEditor.PrefabUtility.GetPrefabType(this) == UnityEditor.PrefabType.Prefab)
|
if (UnityEditor.PrefabUtility.GetPrefabType(this) == UnityEditor.PrefabType.Prefab)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
m_OutputText = GetOutputText();
|
m_OutputText = GetOutputText();
|
||||||
m_ImagesVertexIndex.Clear();
|
m_ImagesVertexIndex.Clear();
|
||||||
foreach (Match match in s_Regex.Matches(m_OutputText))
|
foreach (Match match in s_Regex.Matches(m_OutputText))
|
||||||
|
@ -248,8 +248,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hrefInfo.boxes.Add(new Rect(bounds.min, bounds.size));
|
hrefInfo.boxes.Add(new Rect(bounds.min, bounds.size));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UpdateQuadImage();
|
UpdateQuadImage();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -290,7 +294,8 @@ namespace UnityEngine.UI.Extensions
|
||||||
protected string GetOutputText()
|
protected string GetOutputText()
|
||||||
{
|
{
|
||||||
s_TextBuilder.Length = 0;
|
s_TextBuilder.Length = 0;
|
||||||
m_HrefInfos.Clear();
|
// This also clears the list of boxes in m_HrefInfos created by OnPopulateMesh function, without boxes href wont work, so i commented this
|
||||||
|
//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)
|
||||||
|
@ -309,6 +314,13 @@ namespace UnityEngine.UI.Extensions
|
||||||
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(HrefInfosDoesExists(group.Value,out foundAtIndex)) {
|
||||||
|
m_HrefInfos[foundAtIndex].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;
|
||||||
|
|
||||||
|
} else {
|
||||||
var hrefInfo = new HrefInfo
|
var hrefInfo = new HrefInfo
|
||||||
{
|
{
|
||||||
startIndex = s_TextBuilder.Length * 4, // Hyperlinks in text starting vertex indices
|
startIndex = s_TextBuilder.Length * 4, // Hyperlinks in text starting vertex indices
|
||||||
|
@ -316,6 +328,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
name = group.Value
|
name = group.Value
|
||||||
};
|
};
|
||||||
m_HrefInfos.Add(hrefInfo);
|
m_HrefInfos.Add(hrefInfo);
|
||||||
|
}
|
||||||
|
|
||||||
s_TextBuilder.Append(match.Groups[2].Value);
|
s_TextBuilder.Append(match.Groups[2].Value);
|
||||||
s_TextBuilder.Append("</color>");
|
s_TextBuilder.Append("</color>");
|
||||||
|
@ -326,6 +339,28 @@ namespace UnityEngine.UI.Extensions
|
||||||
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>
|
||||||
|
|
Loading…
Reference in New Issue