mirror of
https://github.com/ConjureETS/Unity_Utils.git
synced 2026-03-24 04:50:58 +00:00
50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
|
|
using JetBrains.Annotations;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace JohnsonUtils.Canvases
|
|
{
|
|
public class TextUIComponent : UIComponentBase
|
|
{
|
|
#if ODIN_INSPECTOR
|
|
[Required]
|
|
#endif
|
|
[Header("Association"), SerializeField]
|
|
private TMP_Text text;
|
|
|
|
private string _initialText;
|
|
|
|
public string Text
|
|
{
|
|
get => text.text;
|
|
set => text.text = string.IsNullOrEmpty(value) ? string.Empty : value;
|
|
}
|
|
|
|
[UsedImplicitly]
|
|
public Color Color
|
|
{
|
|
get => text.color;
|
|
set => text.color = value;
|
|
}
|
|
|
|
private void Awake() => _initialText = text.text;
|
|
|
|
private void Start() => Debug.Assert(text, $"A {nameof(text)} must be assigned to a {nameof(TMP_Text)}");
|
|
|
|
public void ResetText() => text.text = _initialText;
|
|
|
|
[PublicAPI]
|
|
public void AddText(string textToAdd) => text.text += textToAdd;
|
|
|
|
[PublicAPI]
|
|
public void EraseText() => text.text = string.Empty;
|
|
|
|
private void OnValidate()
|
|
{
|
|
if (!text)
|
|
text = GetComponent<TMP_Text>();
|
|
}
|
|
}
|
|
} |