namespace UIWidgets { using System; using UnityEngine; using UnityEngine.UI; /// /// Text adapter to work with both Unity text and TMPro text. /// [AddComponentMenu("UI/New UI Widgets/Adapters/Text Adapter")] public class TextAdapter : MonoBehaviour, ITextProxy { ITextProxy proxy; /// /// Proxy. /// protected ITextProxy Proxy { get { if (proxy == null) { proxy = GetProxy(); } return proxy; } } /// /// Proxy gameobject. /// public GameObject GameObject { get { return Proxy.GameObject; } } /// /// Proxy graphic component. /// public Graphic Graphic { get { return Proxy.Graphic; } } /// /// Proxy color. /// public Color color { get { return Proxy.color; } set { Proxy.color = value; } } /// /// Font size. /// public float fontSize { get { return Proxy.fontSize; } set { Proxy.fontSize = value; } } /// /// Font style. /// public FontStyle fontStyle { get { return Proxy.fontStyle; } set { Proxy.fontStyle = value; } } /// /// Bold. /// public bool Bold { get { return Proxy.Bold; } set { Proxy.Bold = value; } } /// /// Italic. /// public bool Italic { get { return Proxy.Italic; } set { Proxy.Italic = value; } } /// /// Proxy value. /// public string Value { get { return Proxy.text; } set { Proxy.text = value; } } /// /// Proxy value. /// Alias for Value property. /// public string text { get { return Proxy.text; } set { Proxy.text = value; } } /// /// Proxy value. /// Alias for Value property. /// [Obsolete("Renamed to text.")] public string Text { get { return Proxy.text; } set { Proxy.text = value; } } /// /// Get text proxy. /// /// Proxy instance. protected virtual ITextProxy GetProxy() { var text_unity = GetComponent(); if (text_unity != null) { return new TextUnity(text_unity); } #if UIWIDGETS_TMPRO_SUPPORT var text_tmpro = GetComponent(); if (text_tmpro != null) { return new TextTMPro(text_tmpro); } #endif Debug.LogWarning("Not found any Text component. Probably TextMeshPro support is disabled.", this); return new TextNull(); } #if UNITY_EDITOR /// /// Update layout when parameters changed. /// protected virtual void OnValidate() { GetProxy(); } #endif } }