76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class StatsPanelUI : MonoBehaviour
|
|
{
|
|
public PlayerStats playerStats;
|
|
public Text titleText;
|
|
public Text maxHealthText;
|
|
public Text maxManaText;
|
|
public Text damageText;
|
|
public Text moveSpeedText;
|
|
public Text cooldownReductionText;
|
|
public Text criticalChanceText;
|
|
|
|
private void Awake()
|
|
{
|
|
if (playerStats == null)
|
|
{
|
|
playerStats = FindObjectOfType<PlayerStats>();
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (playerStats != null)
|
|
{
|
|
playerStats.OnStatsChanged += Refresh;
|
|
}
|
|
|
|
Refresh();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (playerStats != null)
|
|
{
|
|
playerStats.OnStatsChanged -= Refresh;
|
|
}
|
|
}
|
|
|
|
public void Refresh()
|
|
{
|
|
if (playerStats == null)
|
|
{
|
|
playerStats = FindObjectOfType<PlayerStats>();
|
|
}
|
|
|
|
if (playerStats == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (titleText != null)
|
|
{
|
|
titleText.text = "Характеристики";
|
|
}
|
|
|
|
SetText(maxHealthText, "Max Health", playerStats.MaxHealth, false);
|
|
SetText(maxManaText, "Max Mana", playerStats.MaxMana, false);
|
|
SetText(damageText, "Damage", playerStats.Damage, false);
|
|
SetText(moveSpeedText, "Move Speed", playerStats.MoveSpeed, false);
|
|
SetText(cooldownReductionText, "Cooldown Reduction", playerStats.AbilityCooldownReduction, true);
|
|
SetText(criticalChanceText, "Critical Chance", playerStats.CriticalChance, true);
|
|
}
|
|
|
|
private void SetText(Text text, string label, float value, bool percent)
|
|
{
|
|
if (text == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
text.text = percent ? $"{label}: {value:0.#}%" : $"{label}: {value:0.#}";
|
|
}
|
|
}
|