UI相关优化补充

This commit is contained in:
2026-05-25 13:21:41 +08:00
parent 3c812cfb41
commit a1f9122153
54 changed files with 2008 additions and 112 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using Unity.Profiling;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
@@ -47,6 +48,10 @@ namespace BaseGames.UI.HUD
private readonly CompositeDisposable _subs = new();
private int _lastLingZhu = int.MinValue;
// ── 性能基线 (Profiler 窗口可在 "Scripts" 类别下看到) ──
private static readonly ProfilerMarker s_RebuildHPMarker = new("HUD.RebuildHPCells");
private static readonly ProfilerMarker s_RebuildSpringMarker = new("HUD.RebuildSpringIcons");
private void OnEnable()
{
_onHPChanged?.Subscribe(UpdateHP).AddTo(_subs);
@@ -69,6 +74,7 @@ namespace BaseGames.UI.HUD
private void RebuildHPCells(int max)
{
using var _ = s_RebuildHPMarker.Auto();
if (_hpContainer == null || _hpCellPrefab == null) return;
// 复用现有 Cell仅在数量不足时 Instantiate 补充,超出时 SetActive(false) 而非 Destroy
for (int i = 0; i < max; i++)
@@ -101,6 +107,7 @@ namespace BaseGames.UI.HUD
private void RebuildSpringIcons(int charges)
{
using var _ = s_RebuildSpringMarker.Auto();
if (_springContainer == null || _springIconPrefab == null) return;
// 复用已有图标,超出数量时 SetActive(false)
for (int i = 0; i < charges; i++)