add project files
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user