2025-10-03 00:02:43 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using TMPro;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace Continentis.MainGame.UI
|
|
|
|
|
{
|
|
|
|
|
public partial class HUD_BaseIcon : UIElementBase, IPointerEnterHandler, IPointerExitHandler
|
|
|
|
|
{
|
|
|
|
|
public Image icon;
|
|
|
|
|
public List<TMP_Text> textList;
|
|
|
|
|
public TMP_Text iconText => textList[0];
|
|
|
|
|
|
|
|
|
|
public virtual void UpdateIcon()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnPointerEnter(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void OnPointerExit(PointerEventData eventData)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class HUD_BaseIcon
|
|
|
|
|
{
|
|
|
|
|
public void SetText(int textIndex, Func<string> getText)
|
|
|
|
|
{
|
|
|
|
|
if (textIndex < 0 || textIndex >= textList.Count)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning($"Text index {textIndex} is out of range.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMP_Text text = textList[textIndex];
|
2025-12-14 00:51:34 -05:00
|
|
|
|
|
|
|
|
if (text == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning($"Text component at index {textIndex} is null.");
|
|
|
|
|
// 如果这里触发了,说明上层逻辑在尝试操作一个已经死亡的 UI 对象
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-03 00:02:43 -04:00
|
|
|
if (getText != null)
|
|
|
|
|
{
|
|
|
|
|
text.gameObject.SetActive(true);
|
|
|
|
|
text.text = getText();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
text.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|