Merged in playemgames/unity-ui-extensions-4/playemgames/fixes-to-make-sure-images-align-correctl-1510089190226 (pull request #27)

Fixes to make sure images align correctly and are culled based on the matches for icons in TextPic.
pull/413/head
Brad Nelson 2017-11-20 08:54:36 +00:00 committed by Simon Jackson
commit d3671c3711
1 changed files with 31 additions and 33 deletions

View File

@ -128,23 +128,17 @@ namespace UnityEngine.UI.Extensions {
#endif
m_OutputText = GetOutputText();
m_ImagesVertexIndex.Clear();
MatchCollection matches = s_Regex.Matches(m_OutputText);
if (matches != null && matches.Count > 0) {
foreach (Match match in matches) {
var picIndex = match.Index;
var endIndex = picIndex * 4 + 3;
m_ImagesVertexIndex.Add(endIndex);
for (int i = 0; i < matches.Count; i++) {
m_ImagesPool.RemoveAll(image => image == null);
if (m_ImagesPool.Count == 0) {
GetComponentsInChildren<Image>(true, m_ImagesPool);
}
if (m_ImagesVertexIndex.Count > m_ImagesPool.Count) {
if (matches.Count > m_ImagesPool.Count) {
var resources = new DefaultControls.Resources();
var go = DefaultControls.CreateImage(resources);
go.layer = gameObject.layer;
@ -160,9 +154,9 @@ namespace UnityEngine.UI.Extensions {
m_ImagesPool.Add(go.GetComponent<Image>());
}
var spriteName = match.Groups[1].Value;
var spriteName = matches[i].Groups[1].Value;
var img = m_ImagesPool[m_ImagesVertexIndex.Count - 1];
var img = m_ImagesPool[i];
Vector2 imgoffset = Vector2.zero;
@ -182,8 +176,8 @@ namespace UnityEngine.UI.Extensions {
img.enabled = true;
if (positions.Count == m_ImagesPool.Count) {
img.rectTransform.anchoredPosition = positions[m_ImagesVertexIndex.Count - 1] += imgoffset;
if (positions.Count > 0 && i < positions.Count) {
img.rectTransform.anchoredPosition = positions[i] += imgoffset;
}
}
}
@ -200,7 +194,7 @@ namespace UnityEngine.UI.Extensions {
}
// Remove any images that are not being used
for (var i = m_ImagesVertexIndex.Count; i < m_ImagesPool.Count; i++) {
for (var i = matches.Count; i < m_ImagesPool.Count; i++) {
if (m_ImagesPool[i]) {
if (!culled_ImagesPool.Contains(m_ImagesPool[i].gameObject)) {
culled_ImagesPool.Add(m_ImagesPool[i].gameObject);
@ -227,11 +221,6 @@ namespace UnityEngine.UI.Extensions {
for (var i = 0; i < m_ImagesVertexIndex.Count; i++) {
var endIndex = m_ImagesVertexIndex[i];
if (m_ImagesPool[i] != null) {
var rt = m_ImagesPool[i].rectTransform;
var size = rt.sizeDelta;
if (endIndex < toFill.currentVertCount) {
toFill.PopulateUIVertex(ref vert, endIndex);
positions.Add(new Vector2((vert.position.x + fontSize / 2), (vert.position.y + fontSize / 2)) + imageOffset);
@ -247,11 +236,6 @@ namespace UnityEngine.UI.Extensions {
}
}
}
}
if (m_ImagesVertexIndex.Count != 0) {
m_ImagesVertexIndex.Clear();
}
// Hyperlinks surround processing box
foreach (var hrefInfo in m_HrefInfos) {
@ -377,7 +361,21 @@ namespace UnityEngine.UI.Extensions {
s_TextBuilder.Append(fixedString.Substring(indexText, fixedString.Length - indexText));
return s_TextBuilder.ToString();
m_OutputText = s_TextBuilder.ToString();
m_ImagesVertexIndex.Clear();
MatchCollection matches = s_Regex.Matches(m_OutputText);
if (matches != null && matches.Count > 0) {
foreach (Match match in matches) {
var picIndex = match.Index;
var endIndex = picIndex * 4 + 3;
m_ImagesVertexIndex.Add(endIndex);
}
}
return m_OutputText;
}
/// <summary>