From 292fb39c9396cff0146ff44591994b9e318b1712 Mon Sep 17 00:00:00 2001 From: sushanta chakraborty Date: Tue, 27 Sep 2016 12:38:44 +0000 Subject: [PATCH] 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-1474979920532 --- Scripts/Controls/TextPic.cs | 773 +++++++++++++++++++----------------- 1 file changed, 404 insertions(+), 369 deletions(-) diff --git a/Scripts/Controls/TextPic.cs b/Scripts/Controls/TextPic.cs index f03cf3f..641b8a0 100644 --- a/Scripts/Controls/TextPic.cs +++ b/Scripts/Controls/TextPic.cs @@ -10,421 +10,456 @@ using UnityEngine.EventSystems; 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; + // 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")] - /// - /// Vertex Index - /// - private readonly List m_ImagesVertexIndex = new List(); + [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; - /// - /// Regular expression to replace - /// - private static readonly Regex s_Regex = - new Regex(@"", RegexOptions.Singleline); + /// + /// Vertex Index + /// + private readonly List m_ImagesVertexIndex = new List(); - private string fixedString; + /// + /// Regular expression to replace + /// + private static readonly Regex s_Regex = + new Regex(@"", RegexOptions.Singleline); - public override void SetVerticesDirty() - { - base.SetVerticesDirty(); - UpdateQuadImage(); - } + private string fixedString; -#if UNITY_EDITOR - protected override void OnValidate() - { - base.OnValidate(); - UpdateQuadImage(); - } -#endif + public override void SetVerticesDirty() + { + base.SetVerticesDirty(); + UpdateQuadImage(); + } - /// - /// After parsing the final text - /// - private string m_OutputText; + #if UNITY_EDITOR + protected override void OnValidate() + { + base.OnValidate(); + UpdateQuadImage(); + } + #endif - [System.Serializable] - public struct IconName - { - public string name; - public Sprite sprite; - } - public IconName[] inspectorIconList; + /// + /// After parsing the final text + /// + private string m_OutputText; - private Dictionary iconList = new Dictionary(); + [System.Serializable] + public struct IconName + { + public string name; + public Sprite sprite; + } + public IconName[] inspectorIconList; - public float ImageScalingFactor = 1; + private Dictionary iconList = new Dictionary(); - // Write the name or hex value of the hyperlink color - public string hyperlinkColor = "blue"; + public float ImageScalingFactor = 1; - // Offset image by x, y - [SerializeField] - public Vector2 imageOffset = Vector2.zero; + // Write the name or hex value of the hyperlink color + public string hyperlinkColor = "blue"; - private Button button; + // Offset image by x, y + [SerializeField] + public Vector2 imageOffset = Vector2.zero; - //Commented out as private and not used.. Yet? - //private bool selected = false; + private Button button; - private List positions = new List(); + //Commented out as private and not used.. Yet? + //private bool selected = false; - /** + private List positions = new List(); + + /** * Unity Inspector cant display Dictionary vars, * so we use this little hack to setup the iconList */ - new void Start() - { - button = GetComponent