From f324f580762edd096309968c0880081f14d839bd Mon Sep 17 00:00:00 2001 From: playemgames Date: Fri, 5 Aug 2016 11:36:19 +0000 Subject: [PATCH] Hack to clear out culled images to properly position them instead of reuse images. --HG-- branch : playemgames/hack-to-clear-out-culled-images-to-prope-1470396744892 --- Scripts/Controls/TextPic.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Scripts/Controls/TextPic.cs b/Scripts/Controls/TextPic.cs index 4988f23..f03cf3f 100644 --- a/Scripts/Controls/TextPic.cs +++ b/Scripts/Controls/TextPic.cs @@ -13,12 +13,16 @@ namespace UnityEngine.UI.Extensions // Image according to the label inside the name attribute to load, read from the Resources directory. The size of the image is controlled by the size property. // Use: [AddComponentMenu("UI/Extensions/TextPic")] + + [ExecuteInEditMode] // Needed for culling images that are not used // public class TextPic : Text, IPointerClickHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler { /// /// Image Pool /// private readonly List m_ImagesPool = new List(); + private readonly List culled_ImagesPool = new List(); + private bool clearImages = false; /// /// Vertex Index @@ -162,9 +166,17 @@ namespace UnityEngine.UI.Extensions { if (m_ImagesPool[i]) { - m_ImagesPool[i].enabled = false; + /* TEMPORARY FIX REMOVE IMAGES FROM POOL DELETE LATER SINCE CANNOT DESTROY */ + // m_ImagesPool[i].enabled = false; + m_ImagesPool[i].gameObject.SetActive(false); + m_ImagesPool[i].gameObject.hideFlags = HideFlags.HideAndDontSave; + culled_ImagesPool.Add(m_ImagesPool[i].gameObject); + m_ImagesPool.Remove(m_ImagesPool[i]); } } + if (culled_ImagesPool.Count > 1) { + clearImages = true; + } } protected override void OnPopulateMesh(VertexHelper toFill) @@ -403,5 +415,16 @@ namespace UnityEngine.UI.Extensions public readonly List boxes = new List(); } + + /* TEMPORARY FIX REMOVE IMAGES FROM POOL DELETE LATER SINCE CANNOT DESTROY */ + void Update() { + if (clearImages) { + for (int i = 0; i < culled_ImagesPool.Count; i++){ + DestroyImmediate(culled_ImagesPool[i]); + } + culled_ImagesPool.Clear(); + clearImages = false; + } + } } } \ No newline at end of file