/// Credit drobina, w34edrtfg, playemgames /// Sourced from - http://forum.unity3d.com/threads/sprite-icons-with-text-e-g-emoticons.265927/ using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using UnityEngine.Events; 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: 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 { /// /// Image Pool /// private readonly List m_ImagesPool = new List(); private readonly List culled_ImagesPool = new List(); private bool clearImages = false; private Object thisLock = new Object(); /// /// Vertex Index /// private readonly List m_ImagesVertexIndex = new List(); /// /// Regular expression to replace /// private static readonly Regex s_Regex = new Regex(@"", RegexOptions.Singleline); private string fixedString; [SerializeField] [Tooltip("Allow click events to be received by parents, (default) blocks")] private bool m_ClickParents; // 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; private List positions = new List(); /** * Little hack to support multiple hrefs with same name */ private string previousText = ""; public bool isCreating_m_HrefInfos = true; new void Start() { button = GetComponent