尝试修改丢text的情况

This commit is contained in:
SoulliesOfficial
2025-12-14 00:51:34 -05:00
parent c260d0740c
commit e60ef64d01
12 changed files with 151 additions and 19 deletions

View File

@@ -34,8 +34,18 @@ namespace Continentis.MainGame.UI
HUD_CharacterBuffIcon buffIcon = buffIcons.Find(x => x.buff == buff);
if (buffIcon != null)
{
LeanPool.Despawn(buffIcon.gameObject);
buffIcons.Remove(buffIcon);
buff.iconSubmodule.buffIcon = null;
LeanPool.Despawn(buffIcon.gameObject);
}
else
{
// 如果逻辑上要移除 Buff但在 UI 列表里找不到对应的 Icon说明出事了。
// 这可能是导致你看到“Buff图标没有正常显示”的另一个原因状态不同步
Debug.LogWarning($"[HUD] 尝试移除 Buff {buff.contentSubmodule.displayName} 的图标,但在 buffIcons 列表中未找到匹配项!可能存在状态脱节。");
// 可选:强制清理一遍列表中的空引用(自我修复)
// CleanUpInvalidIcons();
}
UpdateHud();
}

View File

@@ -40,6 +40,14 @@ namespace Continentis.MainGame.UI
}
TMP_Text text = textList[textIndex];
if (text == null)
{
Debug.LogWarning($"Text component at index {textIndex} is null.");
// 如果这里触发了,说明上层逻辑在尝试操作一个已经死亡的 UI 对象
return;
}
if (getText != null)
{
text.gameObject.SetActive(true);