diff --git a/Scripts/Controls/TextPic.cs b/Scripts/Controls/TextPic.cs index 98e9fe2..693b43e 100644 --- a/Scripts/Controls/TextPic.cs +++ b/Scripts/Controls/TextPic.cs @@ -17,12 +17,52 @@ namespace UnityEngine.UI.Extensions { [ExecuteInEditMode] // Needed for culling images that are not used // public class TextPic : Text, IPointerClickHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler { + // Icon entry to replace text with + [Serializable] + public struct IconName { + public string name; + public Sprite sprite; + public Vector2 offset; + public Vector2 scale; + } + + // Icons and text to replace + public IconName[] inspectorIconList; + + [Tooltip("Global scaling factor for all images")] + public float ImageScalingFactor = 1; + + // Write the name or hex value of the hyperlink color + public string hyperlinkColor = "blue"; + + // Offset image by x, y + public Vector2 imageOffset = Vector2.zero; + public bool isCreating_m_HrefInfos = true; + + [Serializable] + public class HrefClickEvent : UnityEvent { } + + [SerializeField] + private HrefClickEvent m_OnHrefClick = new HrefClickEvent(); + + /// + /// Hyperlink Click Event + /// + public HrefClickEvent onHrefClick { + get { return m_OnHrefClick; } + set { m_OnHrefClick = value; } + } + /// /// Image Pool /// private readonly List m_ImagesPool = new List(); private readonly List culled_ImagesPool = new List(); + + // Used for check for culling images private bool clearImages = false; + + // Lock to ensure images get culled properly private Object thisLock = new Object(); /// @@ -36,82 +76,118 @@ namespace UnityEngine.UI.Extensions { private static readonly Regex s_Regex = new Regex(@"", RegexOptions.Singleline); - private string fixedString; [SerializeField] + /// + /// Hyperlink Regular Expression + /// + private static readonly Regex s_HrefRegex = + new Regex(@"\n\s]+)>(.*?)()", RegexOptions.Singleline); - [Tooltip("Allow click events to be received by parents, (default) blocks")] - - private bool m_ClickParents; + // String to create quads + private string fixedString; // 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() { - base.SetVerticesDirty(); - - // Update the quad images - updateQuad = true; - } - -#if UNITY_EDITOR - protected override void OnValidate() { - base.OnValidate(); - - // 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; - } - } - } -#endif - /// /// After parsing the final text /// private string m_OutputText; - [System.Serializable] - public struct IconName { - public string name; - public Sprite sprite; - public Vector2 offset; - public Vector2 scale; - } - - public IconName[] inspectorIconList; - - [Tooltip("Global scaling factor for all images")] - public float ImageScalingFactor = 1; - - // Write the name or hex value of the hyperlink color - public string hyperlinkColor = "blue"; - - // Offset image by x, y - [SerializeField] - public Vector2 imageOffset = Vector2.zero; - private Button button; + // Used for custom selection as a variable for other scripts + private bool selected = false; + + // Positions of images for icon placement private List positions = new List(); - /** - * Little hack 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 = GetComponent