53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using System;
|
|
using Cielonos.MainGame;
|
|
using SLSFramework.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.UI
|
|
{
|
|
public class PlayerInfoUIArea : UIElementBase
|
|
{
|
|
public TMP_Text nameText;
|
|
public TMP_Text healthText;
|
|
public PlayerHealthBar healthBar;
|
|
public PlayerEnergyBar energyBar;
|
|
|
|
private void Start()
|
|
{
|
|
UpdateHealth(true);
|
|
UpdateEnergy(true);
|
|
}
|
|
|
|
public void UpdateHealth(bool isInstant = false)
|
|
{
|
|
float currentHealth = MainGameManager.Player.attributeSm["Health"];
|
|
float maximumHealth = MainGameManager.Player.attributeSm["MaximumHealth"];
|
|
float ratio = currentHealth / maximumHealth;
|
|
Color fillColor = healthBar.GetTargetColor(ratio);
|
|
string colorHex = ColorUtility.ToHtmlStringRGB(fillColor);
|
|
healthBar.UpdateFillImage(currentHealth, maximumHealth);
|
|
healthBar.UpdateFillColor(fillColor, isInstant);
|
|
if(!isInstant) healthBar.Blink(Color.white);
|
|
|
|
int currentHealthInt = Mathf.CeilToInt(currentHealth);
|
|
int maximumHealthInt = Mathf.CeilToInt(maximumHealth);
|
|
if (ratio <= 0.2f)
|
|
{
|
|
healthText.text = $"<color=#{colorHex}>{currentHealthInt}</color> <size=18>/ {maximumHealthInt}</size>";
|
|
}
|
|
else
|
|
{
|
|
healthText.text = $"{currentHealthInt} <size=18>/ {maximumHealthInt}</size>";
|
|
}
|
|
}
|
|
|
|
public void UpdateEnergy(bool isInstant = false)
|
|
{
|
|
float currentEnergy = MainGameManager.Player.attributeSm["Energy"];
|
|
float maximumEnergy = MainGameManager.Player.attributeSm["MaximumEnergy"];
|
|
energyBar.UpdateFillImage(currentEnergy, maximumEnergy);
|
|
if(!isInstant) energyBar.Blink(Color.white);
|
|
}
|
|
}
|
|
} |