2025-10-03 00:02:43 -04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Continentis.MainGame.Character;
|
|
|
|
|
|
using Lean.Pool;
|
2026-04-17 12:01:50 -04:00
|
|
|
|
using SLSUtilities.General;
|
2025-10-03 00:02:43 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Continentis.MainGame.UI
|
|
|
|
|
|
{
|
|
|
|
|
|
public class HUD_CharacterBuffCollection : HUDElementBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public RectTransform buffContainer;
|
|
|
|
|
|
public GameObject buffIconPrefab;
|
|
|
|
|
|
public List<HUD_CharacterBuffIcon> buffIcons;
|
|
|
|
|
|
|
|
|
|
|
|
public override void UpdateHud()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var buffIcon in buffIcons)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffIcon.UpdateIcon();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddBuffIcon(CharacterBuffBase buff)
|
|
|
|
|
|
{
|
|
|
|
|
|
HUD_CharacterBuffIcon buffIcon = LeanPool.Spawn(buffIconPrefab, buffContainer).GetComponent<HUD_CharacterBuffIcon>();
|
|
|
|
|
|
buffIcon.Initialize(buff);
|
2025-10-24 09:11:22 -04:00
|
|
|
|
buffIcons.AddByPriority(buffIcon);
|
|
|
|
|
|
buffIcon.transform.SetSiblingIndex(buffIcons.IndexOf(buffIcon));
|
2025-10-03 00:02:43 -04:00
|
|
|
|
UpdateHud();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveBuffIcon(CharacterBuffBase buff)
|
|
|
|
|
|
{
|
|
|
|
|
|
HUD_CharacterBuffIcon buffIcon = buffIcons.Find(x => x.buff == buff);
|
|
|
|
|
|
if (buffIcon != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
buffIcons.Remove(buffIcon);
|
2025-12-14 00:51:34 -05:00
|
|
|
|
buff.iconSubmodule.buffIcon = null;
|
|
|
|
|
|
LeanPool.Despawn(buffIcon.gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 如果逻辑上要移除 Buff,但在 UI 列表里找不到对应的 Icon,说明出事了。
|
|
|
|
|
|
// 这可能是导致你看到“Buff图标没有正常显示”的另一个原因(状态不同步)。
|
|
|
|
|
|
Debug.LogWarning($"[HUD] 尝试移除 Buff {buff.contentSubmodule.displayName} 的图标,但在 buffIcons 列表中未找到匹配项!可能存在状态脱节。");
|
|
|
|
|
|
|
|
|
|
|
|
// 可选:强制清理一遍列表中的空引用(自我修复)
|
|
|
|
|
|
// CleanUpInvalidIcons();
|
2025-10-03 00:02:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
UpdateHud();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|