Files
test/Assets/PerfectWorld/Scripts/UI/HUDNPC.cs
Chomper9981 d5adc1542c Update UI
2026-03-02 18:02:23 +07:00

58 lines
1.6 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
using BrewMonster.Network;
using CSNetwork.GPDataType;
namespace BrewMonster
{
public class HUDNPC : MonoBehaviour
{
[SerializeField] private Button _NPCIconBtn;
[SerializeField] private TextMeshProUGUI _healthText;
[SerializeField] private TextMeshProUGUI _nameText;
[SerializeField] private TextMeshProUGUI _statText;
[SerializeField] private Image healthImage;
private void OnEnable()
{
if (_NPCIconBtn != null)
{
_NPCIconBtn.onClick.AddListener(OnNPCIconBtnClick);
}
}
private void OnDisable()
{
if (_NPCIconBtn != null)
{
_NPCIconBtn.onClick.RemoveListener(OnNPCIconBtnClick);
}
}
private void OnNPCIconBtnClick()
{
var host = EC_Game.GetGameRun()?.GetHostPlayer();
if (host == null)
return;
int id = host.GetSelectedTarget();
if (id == 0 || id == host.GetCharacterID() || !GPDataTypeHelper.ISPLAYERID(id))
return;
CECUIManager.Instance?.ShowPlayerOptionsDialog(id, _NPCIconBtn.transform.position);
}
public void SetText(string healthText, string nameText, string statText)
{
_healthText.text = healthText;
_nameText.text = nameText;
_statText.text = statText;
}
public void SetHealthImage(float health)
{
healthImage.fillAmount = health;
}
}
}