为 RepoItem 添加背景耐久变色

This commit is contained in:
SepComet
2026-03-04 19:17:13 +08:00
parent 1e5803f4c5
commit 298345fa17
10 changed files with 424 additions and 232 deletions
@@ -9,11 +9,13 @@ namespace GeometryTD.UI
{
public class RepoItem : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
[SerializeField] private Image _highlightImage;
[SerializeField] private Image _bgImage;
[SerializeField] private IconArea _iconArea;
private static readonly Color NormalColor = new Color32(40, 40, 40, 180);
private static readonly Color SelectedColor = new Color32(255, 216, 102, 255);
private static readonly Color EmptyEnduranceColor = new Color(0.8f, 0f, 0f, 1f);
private static readonly Color FullEnduranceColor = new Color(0f, 0.8f, 0f, 1f);
private static readonly Vector2 DefaultDragGhostSize = new Vector2(64f, 64f);
[SerializeField] private RepoItemContext _context;
@@ -74,12 +76,24 @@ namespace GeometryTD.UI
public void SetSelected(bool isSelected)
{
_isSelected = isSelected;
if (_highlightImage == null)
RefreshBackgroundColor();
}
private void RefreshBackgroundColor()
{
if (_bgImage == null)
{
return;
}
_highlightImage.color = isSelected ? SelectedColor : NormalColor;
if (_isSelected)
{
_bgImage.color = SelectedColor;
return;
}
float enduranceRate = _context != null ? Mathf.Clamp01(_context.EnduranceRate01) : 1f;
_bgImage.color = Color.Lerp(EmptyEnduranceColor, FullEnduranceColor, enduranceRate);
}
public void OnClick()