mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 07:17:14 +08:00
(client) feat:健康给予,路径优化,结算界面,商店界面 (#60)
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
This commit is contained in:
@@ -1,20 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Entity;
|
||||
using Prefab;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class BuffIconListUI: MonoBehaviour
|
||||
public class BuffIconListUI : MonoBehaviour
|
||||
{
|
||||
public BuffIconUI prefab;
|
||||
public Transform container;
|
||||
private readonly List<BuffIconUI> icons = new(); // 用于存储所有的图标
|
||||
|
||||
public LivingEntity CurrentEntity { get; private set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
foreach (Transform child in container)
|
||||
foreach (Transform child in container) Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Program.Instance.OnFocusedEntityChanged += FocusedEntityChanged;
|
||||
FocusedEntityChanged(Program.Instance.FocusedEntity);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Program.Instance.OnFocusedEntityChanged -= FocusedEntityChanged;
|
||||
}
|
||||
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (!CurrentEntity)
|
||||
return;
|
||||
var buffes = CurrentEntity.Hediffs;
|
||||
var icons = SetIconCount(buffes.Count);
|
||||
for (var i = 0; i < buffes.Count; i++) icons[i].Init(buffes[i]);
|
||||
}
|
||||
|
||||
public List<BuffIconUI> SetIconCount(int count)
|
||||
{
|
||||
// 清空现有子对象
|
||||
while (icons.Count > count)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
Destroy(icons[icons.Count - 1].gameObject);
|
||||
icons.RemoveAt(icons.Count - 1);
|
||||
}
|
||||
|
||||
// 添加新子对象
|
||||
while (icons.Count < count)
|
||||
{
|
||||
var newIcon = Instantiate(prefab, container);
|
||||
icons.Add(newIcon);
|
||||
}
|
||||
|
||||
return icons;
|
||||
}
|
||||
|
||||
public void FocusedEntityChanged(Entity.Entity entity)
|
||||
{
|
||||
CurrentEntity = entity as LivingEntity;
|
||||
UpdateUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user