Files
Emberwild/Assets/GAME/Script/UI/BuildCostEntryUI.cs
T
2026-07-22 12:56:13 +02:00

57 lines
2.0 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Ashwild.UI
{
/// <summary>
/// One resource line of a build's cost, shown near the crosshair while placing: an icon plus an
/// "owned / required" count (e.g. 2/3). A pure, data-agnostic view — it is handed an icon, the two
/// numbers and an "affordable" flag and renders exactly that (tinting the count to signal a
/// shortfall), never resolving any domain data itself. Authored as pre-placed children of the
/// crosshair's cost holder — CrosshairManager fills and shows/hides them, it does not instantiate.
/// </summary>
[DisallowMultipleComponent]
public class BuildCostEntryUI : MonoBehaviour
{
#region Serialized Fields
[Header("References")]
[Tooltip("Icon of the required resource.")]
[SerializeField] private Image icon;
[Tooltip("Owned / required count for one placement (e.g. 2/3).")]
[SerializeField] private TMP_Text amountLabel;
[Header("Affordability Colours")]
[Tooltip("Amount colour when the player holds enough of this resource.")]
[SerializeField] private Color affordColor = Color.white;
[Tooltip("Amount colour when the player is short of this resource.")]
[SerializeField] private Color missingColor = new Color(1f, 0.35f, 0.35f);
#endregion
#region Public API
/// <summary>
/// Fills the line: sets the icon, the "owned / required" count, and tints it by affordability.
/// </summary>
public void Set(Sprite resourceIcon, int owned, int amount, bool affordable)
{
if (icon != null)
{
icon.sprite = resourceIcon;
icon.enabled = resourceIcon != null;
}
if (amountLabel != null)
{
amountLabel.text = $"{owned}/{amount}";
amountLabel.color = affordable ? affordColor : missingColor;
}
}
#endregion
}
}