rabidus-test/Assets/UITextDisplayBase.cs

33 lines
749 B
C#
Raw 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]
protected string _postfix;
protected virtual void Awake()
{
_text = GetComponent<TMPro.TextMeshProUGUI>();
}
protected virtual void OnEnable()
{
_textChanger.OnTextChange.AddListener(UpdateText);
}
protected virtual void OnDisable()
{
_textChanger.OnTextChange.RemoveListener(UpdateText);
}
private void UpdateText(object obj)
{
_text.SetText(obj.ToString() + _postfix);
}
}