为 RepoItem 添加背景耐久变色
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user