first commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using OTG.Lab06.Abilities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace OTG.Lab06.UI
|
||||
{
|
||||
public sealed class TooltipUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Text titleLabel;
|
||||
[SerializeField] private Text descriptionLabel;
|
||||
[SerializeField] private Text statsLabel;
|
||||
|
||||
private RectTransform rectTransform;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rectTransform = transform as RectTransform;
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Show(AbilityData data, RectTransform anchor)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rectTransform == null)
|
||||
{
|
||||
rectTransform = transform as RectTransform;
|
||||
}
|
||||
|
||||
titleLabel.text = data.abilityName;
|
||||
descriptionLabel.text = data.description;
|
||||
statsLabel.text = $"Damage: {Mathf.RoundToInt(data.damage)}\nMana: {Mathf.RoundToInt(data.manaCost)}\nCooldown: {data.cooldown:0.#}s";
|
||||
gameObject.SetActive(true);
|
||||
|
||||
if (rectTransform != null && anchor != null)
|
||||
{
|
||||
rectTransform.position = anchor.position + new Vector3(0f, 142f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user