72 lines
2.0 KiB
C#
72 lines
2.0 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;
|
|
[SerializeField] private RawImage _avatarImage;
|
|
|
|
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;
|
|
}
|
|
|
|
public void SetAvatar(Texture tex)
|
|
{
|
|
if (_avatarImage == null) return;
|
|
_avatarImage.texture = tex;
|
|
_avatarImage.gameObject.SetActive(tex != null);
|
|
}
|
|
|
|
public void ShowAvatar(bool show)
|
|
{
|
|
if (_avatarImage != null)
|
|
_avatarImage.gameObject.SetActive(show);
|
|
}
|
|
}
|
|
}
|