public void ToggleTextMeshPro(bool on) { if (on) { // if we're already using TextMeshPro; do nothing if (TextComponentWrapper != null && TextComponentWrapper.xmlElement != null && TextComponentWrapper.xmlElement.tagType == "TextMeshPro") { return; } var tmp = gameObject.GetComponentInChildren <TMPro.TextMeshProUGUI>(true); XmlElement tmpXmlElement = null; if (tmp == null) { // create instance var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("TextMeshPro"); tmpXmlElement = tagHandler.GetInstance(this.rectTransform, xmlLayout); tagHandler.SetInstance(tmpXmlElement); tagHandler.ApplyAttributes(new AttributeDictionary()); tmp = tmpXmlElement.GetComponent <TMPro.TextMeshProUGUI>(); tmp.rectTransform.localScale = Vector3.one; } tmpXmlElement = tmp.GetComponent <XmlElement>(); TextComponentWrapper = new TextComponentWrapper(tmp); // hide the regular text component TextComponent.gameObject.SetActive(false); // enable the TMP object if it wasn't already tmp.gameObject.SetActive(true); } else { if (TextComponentWrapper != null && TextComponentWrapper.xmlElement != null && TextComponentWrapper.xmlElement.tagType == "Text") { return; } TextComponentWrapper = new TextComponentWrapper(TextComponent); TextComponent.gameObject.SetActive(true); var tmp = gameObject.GetComponentInChildren <TMPro.TextMeshProUGUI>(); if (tmp != null) { tmp.gameObject.SetActive(false); } } }
private void Start() { if (started) return; TextComponentWrapper = new TextComponentWrapper(TextComponent); TextComponentWrapper.xmlElement.Initialise(xmlLayout, TextComponentWrapper.xmlElement.rectTransform, XmlLayoutUtilities.GetXmlTagHandler("Text")); contentSizeFitter = this.GetComponent<ContentSizeFitter>(); started = true; }