53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using System.Collections.Generic;
|
||
using Continentis.MainGame.Character;
|
||
using Lean.Pool;
|
||
using SLSFramework.General;
|
||
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);
|
||
buffIcons.AddByPriority(buffIcon);
|
||
buffIcon.transform.SetSiblingIndex(buffIcons.IndexOf(buffIcon));
|
||
UpdateHud();
|
||
}
|
||
|
||
public void RemoveBuffIcon(CharacterBuffBase buff)
|
||
{
|
||
HUD_CharacterBuffIcon buffIcon = buffIcons.Find(x => x.buff == buff);
|
||
if (buffIcon != null)
|
||
{
|
||
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();
|
||
}
|
||
}
|
||
} |