Files
test/Assets/PerfectWorld/Scripts/UI/GamePlay/UINPC.cs
T
2026-01-23 14:10:56 +07:00

96 lines
2.8 KiB
C#

using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster
{
public enum IconTaskType
{
QI_NONE = -1,
QI_OUT = 2, // task tu chan (nhan)
QI_IN = 2, // task tu chan (hoan thanh)
QI_OUT_N = 3, // chua du dieu kien nhan task
QI_IN_N = 3, // task nhan nhung chua lam (chua xong)
QI_OUT_K = 0, // chua biet
QI_IN_K = 5, // chua biet
QI_OUT_TYPE1 = 5, // task bang hoi (nhan)
QI_IN_TYPE1 = 5, // task bang hoi (hoan thanh)
QI_OUT_TYPE2 = 1, // chua biet
QI_IN_TYPE2 = 1, // chua biet
QI_OUT_TYPE3 = -1, // task daily (nhan)
QI_IN_TYPE3 = -1, // task daily (hoan thanh)
QI_OUT_TYPE4 = 0, // task chinh (nhan)
QI_IN_TYPE4 = 4, // task chinh (hoan thanh)
}
public class UINPC : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI _nameText;
[SerializeField] private TextMeshProUGUI _healthText;
[SerializeField] private Image _healthImage;
[Header("List Icon Task")]
[SerializeField] private GameObject _iconTaskMain;
[SerializeField] private List<Sprite> _listIconTask;
private Image _cachedIconImage;
private void Awake()
{
if (_iconTaskMain != null)
{
_cachedIconImage = _iconTaskMain.GetComponent<Image>();
if (_cachedIconImage == null)
{
BMLogger.LogError($"[UINPC] _iconTaskMain doesn't have Image component!");
}
}
}
// Start is called once before the first execution of Update after the MonoBehaviour is created
public void SetName(string name)
{
_nameText.text = name;
}
public void SetHealthImage(float health)
{
if(_healthImage != null)
_healthImage.fillAmount = health;
}
public void SetHealthText(string healthText)
{
if(_healthText != null)
_healthText.text = healthText;
}
public void SetTaskIcon(IconTaskType iconType)
{
if (_iconTaskMain == null || _cachedIconImage == null)
{
return;
}
int iconIndex = (int)iconType;
if (iconIndex >= 0 && _listIconTask != null && iconIndex < _listIconTask.Count)
{
_cachedIconImage.sprite = _listIconTask[iconIndex];
_iconTaskMain.SetActive(true);
}
else
{
_iconTaskMain.SetActive(false);
}
}
public void SetTaskIconMain(bool isShow)
{
if (_iconTaskMain != null)
_iconTaskMain.SetActive(isShow);
}
}
}