131 lines
3.8 KiB
C#
131 lines
3.8 KiB
C#
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public enum IconTaskType
|
|
{
|
|
QI_NONE = -1,
|
|
QI_OUT = 0, // task tu chan (nhan)
|
|
QI_IN = 1, // task tu chan (hoan thanh)
|
|
QI_OUT_N = 2, // chua du dieu kien nhan task
|
|
QI_IN_N = 3, // task nhan nhung chua lam (chua xong)
|
|
QI_OUT_K = 4, // chua biet
|
|
QI_IN_K = 5, // chua biet
|
|
|
|
QI_OUT_TYPE1 = 6, // task bang hoi (nhan)
|
|
QI_IN_TYPE1 = 7, // task bang hoi (hoan thanh)
|
|
QI_OUT_TYPE2 = 8, // chua biet
|
|
QI_IN_TYPE2 = 9, // chua biet
|
|
QI_OUT_TYPE3 = 10, // task daily (nhan)
|
|
QI_IN_TYPE3 = 11, // task daily (hoan thanh)
|
|
QI_OUT_TYPE4 = 12, // task chinh (nhan)
|
|
QI_IN_TYPE4 = 13, // task chinh (hoan thanh)
|
|
}
|
|
|
|
[RequireComponent(typeof(NameplateWorldAnchor))]
|
|
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;
|
|
|
|
[Header("World Nameplate")]
|
|
[SerializeField] private Transform _canvasRoot;
|
|
|
|
private NameplateWorldAnchor _nameplateAnchor;
|
|
private Image _cachedIconImage;
|
|
|
|
private void Awake()
|
|
{
|
|
CacheRefs();
|
|
_nameplateAnchor = GetComponent<NameplateWorldAnchor>();
|
|
if (_iconTaskMain != null)
|
|
{
|
|
_cachedIconImage = _iconTaskMain.GetComponent<Image>();
|
|
if (_cachedIconImage == null)
|
|
{
|
|
BMLogger.LogError($"[UINPC] _iconTaskMain doesn't have Image component!");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
ApplyInitialCanvasRootPosition();
|
|
}
|
|
|
|
/// <summary>
|
|
/// World position for the nameplate root is applied once at startup (no per-frame follow).
|
|
/// 名牌根节点世界坐标仅在启动时设置一次(不做每帧跟随)。
|
|
/// </summary>
|
|
private void ApplyInitialCanvasRootPosition()
|
|
{
|
|
if (_canvasRoot == null)
|
|
{
|
|
return;
|
|
}
|
|
if (_nameplateAnchor != null && _nameplateAnchor.TryGetWorldPosition(out var worldPos))
|
|
{
|
|
_canvasRoot.position = worldPos;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
private void CacheRefs()
|
|
{
|
|
if (_canvasRoot == null)
|
|
{
|
|
_canvasRoot = transform;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|