50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public abstract class UnitPlacementButton : PlacementButton
|
|
{
|
|
[SerializeField]
|
|
protected Sprite _detectionRangeSprite;
|
|
|
|
[SerializeField]
|
|
protected int _wood;
|
|
[SerializeField]
|
|
protected int _rock;
|
|
[SerializeField]
|
|
protected int _food;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _foodLabel;
|
|
[SerializeField]
|
|
private TMP_Text _woodLabel;
|
|
[SerializeField]
|
|
private TMP_Text _rockLabel;
|
|
|
|
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
|
|
SetTextFor(_foodLabel, _food);
|
|
SetTextFor(_rockLabel, _rock);
|
|
SetTextFor(_woodLabel, _wood);
|
|
}
|
|
void SetTextFor(TMP_Text label, int value)
|
|
{
|
|
label.transform.parent.gameObject.SetActive(value > 0);
|
|
label.text = "" + value;
|
|
}
|
|
public override void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
base.OnPointerDown(eventData);
|
|
if (Placeholder is UnitPlaceholder placeHolder)
|
|
{
|
|
placeHolder.Rock = _rock;
|
|
placeHolder.Wood = _wood;
|
|
placeHolder.Food = _food;
|
|
}
|
|
}
|
|
}
|