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
commit
d3671c3711
|
@ -128,23 +128,17 @@ namespace UnityEngine.UI.Extensions {
|
||||||
#endif
|
#endif
|
||||||
m_OutputText = GetOutputText();
|
m_OutputText = GetOutputText();
|
||||||
|
|
||||||
m_ImagesVertexIndex.Clear();
|
|
||||||
|
|
||||||
MatchCollection matches = s_Regex.Matches(m_OutputText);
|
MatchCollection matches = s_Regex.Matches(m_OutputText);
|
||||||
|
|
||||||
if (matches != null && matches.Count > 0) {
|
if (matches != null && matches.Count > 0) {
|
||||||
foreach (Match match in matches) {
|
for (int i = 0; i < matches.Count; i++) {
|
||||||
var picIndex = match.Index;
|
|
||||||
var endIndex = picIndex * 4 + 3;
|
|
||||||
m_ImagesVertexIndex.Add(endIndex);
|
|
||||||
|
|
||||||
m_ImagesPool.RemoveAll(image => image == null);
|
m_ImagesPool.RemoveAll(image => image == null);
|
||||||
|
|
||||||
if (m_ImagesPool.Count == 0) {
|
if (m_ImagesPool.Count == 0) {
|
||||||
GetComponentsInChildren<Image>(true, m_ImagesPool);
|
GetComponentsInChildren<Image>(true, m_ImagesPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ImagesVertexIndex.Count > m_ImagesPool.Count) {
|
if (matches.Count > m_ImagesPool.Count) {
|
||||||
var resources = new DefaultControls.Resources();
|
var resources = new DefaultControls.Resources();
|
||||||
var go = DefaultControls.CreateImage(resources);
|
var go = DefaultControls.CreateImage(resources);
|
||||||
go.layer = gameObject.layer;
|
go.layer = gameObject.layer;
|
||||||
|
@ -160,9 +154,9 @@ namespace UnityEngine.UI.Extensions {
|
||||||
m_ImagesPool.Add(go.GetComponent<Image>());
|
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;
|
Vector2 imgoffset = Vector2.zero;
|
||||||
|
|
||||||
|
@ -182,8 +176,8 @@ namespace UnityEngine.UI.Extensions {
|
||||||
|
|
||||||
img.enabled = true;
|
img.enabled = true;
|
||||||
|
|
||||||
if (positions.Count == m_ImagesPool.Count) {
|
if (positions.Count > 0 && i < positions.Count) {
|
||||||
img.rectTransform.anchoredPosition = positions[m_ImagesVertexIndex.Count - 1] += imgoffset;
|
img.rectTransform.anchoredPosition = positions[i] += imgoffset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +194,7 @@ namespace UnityEngine.UI.Extensions {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any images that are not being used
|
// 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 (m_ImagesPool[i]) {
|
||||||
if (!culled_ImagesPool.Contains(m_ImagesPool[i].gameObject)) {
|
if (!culled_ImagesPool.Contains(m_ImagesPool[i].gameObject)) {
|
||||||
culled_ImagesPool.Add(m_ImagesPool[i].gameObject);
|
culled_ImagesPool.Add(m_ImagesPool[i].gameObject);
|
||||||
|
@ -227,32 +221,22 @@ namespace UnityEngine.UI.Extensions {
|
||||||
for (var i = 0; i < m_ImagesVertexIndex.Count; i++) {
|
for (var i = 0; i < m_ImagesVertexIndex.Count; i++) {
|
||||||
var endIndex = m_ImagesVertexIndex[i];
|
var endIndex = m_ImagesVertexIndex[i];
|
||||||
|
|
||||||
if (m_ImagesPool[i] != null) {
|
if (endIndex < toFill.currentVertCount) {
|
||||||
var rt = m_ImagesPool[i].rectTransform;
|
toFill.PopulateUIVertex(ref vert, endIndex);
|
||||||
|
positions.Add(new Vector2((vert.position.x + fontSize / 2), (vert.position.y + fontSize / 2)) + imageOffset);
|
||||||
|
|
||||||
var size = rt.sizeDelta;
|
// Erase the lower left corner of the black specks
|
||||||
|
toFill.PopulateUIVertex(ref vert, endIndex - 3);
|
||||||
|
var pos = vert.position;
|
||||||
|
|
||||||
if (endIndex < toFill.currentVertCount) {
|
for (int j = endIndex, m = endIndex - 3; j > m; j--) {
|
||||||
toFill.PopulateUIVertex(ref vert, endIndex);
|
toFill.PopulateUIVertex(ref vert, endIndex);
|
||||||
positions.Add(new Vector2((vert.position.x + fontSize / 2), (vert.position.y + fontSize / 2)) + imageOffset);
|
vert.position = pos;
|
||||||
|
toFill.SetUIVertex(vert, j);
|
||||||
// Erase the lower left corner of the black specks
|
|
||||||
toFill.PopulateUIVertex(ref vert, endIndex - 3);
|
|
||||||
var pos = vert.position;
|
|
||||||
|
|
||||||
for (int j = endIndex, m = endIndex - 3; j > m; j--) {
|
|
||||||
toFill.PopulateUIVertex(ref vert, endIndex);
|
|
||||||
vert.position = pos;
|
|
||||||
toFill.SetUIVertex(vert, j);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ImagesVertexIndex.Count != 0) {
|
|
||||||
m_ImagesVertexIndex.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hyperlinks surround processing box
|
// Hyperlinks surround processing box
|
||||||
foreach (var hrefInfo in m_HrefInfos) {
|
foreach (var hrefInfo in m_HrefInfos) {
|
||||||
hrefInfo.boxes.Clear();
|
hrefInfo.boxes.Clear();
|
||||||
|
@ -377,7 +361,21 @@ namespace UnityEngine.UI.Extensions {
|
||||||
|
|
||||||
s_TextBuilder.Append(fixedString.Substring(indexText, fixedString.Length - indexText));
|
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>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue