using System; using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.Serialization; [Serializable] public class TextWrapper : MonoBehaviour { [SerializeField] [FormerlySerializedAs("autoFind")] private bool _autoFind = true; [SerializeField] public Text[] uiTexts; public TextMeshProUGUI[] tmTexts; private bool _autoFindDone; private string _text; public string text { get { return _text; } set { _text = value; AutoFind(); if (tmTexts != null) { for (int i = 0; i < tmTexts.Length; i++) { tmTexts[i].text = _text; } } if (uiTexts != null) { for (int i = 0; i < uiTexts.Length; i++) { uiTexts[i].text = _text; } } } } public void Awake() { AutoFind(); } private void AutoFind() { if (!_autoFind || _autoFindDone) { return; } uiTexts = GetComponentsInChildren(); tmTexts = GetComponentsInChildren(); _autoFindDone = true; } }