You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
831 B
C#
39 lines
831 B
C#
2 months ago
|
using UnityEngine;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Linq;
|
||
|
using TMPro;
|
||
|
|
||
|
namespace D2D.UI
|
||
|
{
|
||
|
public abstract class LabelBase : MonoBehaviour
|
||
|
{
|
||
|
[SerializeField] private TMP_Text _label;
|
||
|
[SerializeField] private string _preText;
|
||
|
|
||
|
protected virtual float UpdateRate => -1;
|
||
|
|
||
|
protected virtual float StartRate => 0;
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
Redraw();
|
||
|
|
||
|
if (UpdateRate > 0)
|
||
|
InvokeRepeating(nameof(Redraw), StartRate, UpdateRate);
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
if (UpdateRate < 0)
|
||
|
Redraw();
|
||
|
}
|
||
|
|
||
|
private void Redraw()
|
||
|
{
|
||
|
_label.text = $"{_preText}{GetText()}";
|
||
|
}
|
||
|
|
||
|
protected abstract string GetText();
|
||
|
}
|
||
|
}
|