rabidus-test/Assets/Scripts/UITextDisplayBase.cs

38 lines
920 B
C#
Raw Permalink Normal View History

2023-08-15 17:38:54 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(TMPro.TextMeshProUGUI))]
public class UITextDisplayBase : MonoBehaviour
{
protected TMPro.TextMeshProUGUI _text;
protected ITextChangable _textChanger;
[SerializeField]
2023-08-22 15:41:12 +03:00
protected string _defaultValue = string.Empty;
[SerializeField]
protected string _prefix;
[SerializeField]
2023-08-15 17:38:54 +03:00
protected string _postfix;
protected virtual void Awake()
{
_text = GetComponent<TMPro.TextMeshProUGUI>();
2023-08-22 15:41:12 +03:00
_text.SetText(_defaultValue);
2023-08-15 17:38:54 +03:00
}
protected virtual void OnEnable()
{
_textChanger.OnTextChange.AddListener(UpdateText);
}
protected virtual void OnDisable()
{
_textChanger.OnTextChange.RemoveListener(UpdateText);
}
private void UpdateText(object obj)
{
2023-08-22 15:41:12 +03:00
_text.SetText(_prefix + obj.ToString() + _postfix);
2023-08-15 17:38:54 +03:00
}
}