From db2844d8bd22a2f76a1237a3e8c8e6e13fbddc99 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Mon, 6 Nov 2017 20:44:20 +0000 Subject: [PATCH] Fixed rebuild loop error in TextPic and added disabling/enabling images when the TextPic component is disabled/enabled. --- Scripts/Controls/TextPic.cs | 481 ++++++++++++++++++++---------------- 1 file changed, 263 insertions(+), 218 deletions(-) diff --git a/Scripts/Controls/TextPic.cs b/Scripts/Controls/TextPic.cs index ec737ce..50311af 100644 --- a/Scripts/Controls/TextPic.cs +++ b/Scripts/Controls/TextPic.cs @@ -8,15 +8,15 @@ using System.Text.RegularExpressions; using UnityEngine.Events; using UnityEngine.EventSystems; -namespace UnityEngine.UI.Extensions -{ +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: + + // Use: Add Icon name and sprite to the icons list + [AddComponentMenu("UI/Extensions/TextPic")] [ExecuteInEditMode] // Needed for culling images that are not used // - public class TextPic : Text, IPointerClickHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler - { + public class TextPic : Text, IPointerClickHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler { /// /// Image Pool /// @@ -25,9 +25,6 @@ namespace UnityEngine.UI.Extensions private bool clearImages = false; private Object thisLock = new Object(); - - - /// /// Vertex Index /// @@ -39,33 +36,36 @@ namespace UnityEngine.UI.Extensions private static readonly Regex s_Regex = new Regex(@"", RegexOptions.Singleline); - private string fixedString; + private string fixedString; [SerializeField] - [SerializeField] [Tooltip("Allow click events to be received by parents, (default) blocks")] + private bool m_ClickParents; - public bool AllowClickParents - { + // Update the quad images when true + private bool updateQuad = false; + + public bool AllowClickParents { get { return m_ClickParents; } set { m_ClickParents = value; } } - public override void SetVerticesDirty() - { + public override void SetVerticesDirty() { base.SetVerticesDirty(); - UpdateQuadImage(); + + // Update the quad images + updateQuad = true; } #if UNITY_EDITOR - protected override void OnValidate() - { + protected override void OnValidate() { base.OnValidate(); - UpdateQuadImage(); - for (int i = 0; i < inspectorIconList.Length; i++) - { - if (inspectorIconList[i].scale == Vector2.zero) - { + + // Update the quad images + updateQuad = true; + + for (int i = 0; i < inspectorIconList.Length; i++) { + if (inspectorIconList[i].scale == Vector2.zero) { inspectorIconList[i].scale = Vector2.one; } } @@ -78,16 +78,16 @@ namespace UnityEngine.UI.Extensions private string m_OutputText; [System.Serializable] - public struct IconName - { + public struct IconName { public string name; public Sprite sprite; - public Vector2 offset; - public Vector2 scale; + public Vector2 offset; + public Vector2 scale; } + public IconName[] inspectorIconList; - [Tooltip("Global scaling factor for all images")] + [Tooltip("Global scaling factor for all images")] public float ImageScalingFactor = 1; // Write the name or hex value of the hyperlink color @@ -98,125 +98,124 @@ namespace UnityEngine.UI.Extensions public Vector2 imageOffset = Vector2.zero; private Button button; - private Selectable highlightselectable; //Commented out as private and not used.. Yet? - //private bool selected = false; + private bool selected = false; private List positions = new List(); /** - * Little heck to support multiple hrefs with same name + * Little hack to support multiple hrefs with same name */ private string previousText = ""; public bool isCreating_m_HrefInfos = true; - - new void Start() - { - button = GetComponentInParent