Files
Continentis/Assets/Scripts/MainGame/UI/HUDPage/HUDElements/HUD_CharacterBuffCollection.cs
2025-12-14 00:51:34 -05:00

53 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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();
}
}
}