Files
butchers-games-test/Assets/Scripts/Toolkit/TextWrapper.cs
T
Boris Nikolaev 5f1e94b653 add project files
2026-08-14 01:58:31 +03:00

65 lines
980 B
C#

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<Text>();
tmTexts = GetComponentsInChildren<TextMeshProUGUI>();
_autoFindDone = true;
}
}