44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Text.RegularExpressions;
|
|
using Fruitomation.Game;
|
|
using UnityEngine.UI;
|
|
using UnityEngine;
|
|
|
|
namespace Fruitomation.UI
|
|
{
|
|
public class BuildingUnlockButton : MonoBehaviour
|
|
{
|
|
[Header("Settings")]
|
|
[SerializeField] private BuildingUnlock Building;
|
|
[SerializeField] private CurrencyAmount Cost;
|
|
|
|
[Header("References")]
|
|
[SerializeField] private Button AttachedButton;
|
|
[SerializeField] private Text AttachedText;
|
|
|
|
private void Awake()
|
|
{
|
|
string formatted = Regex.Replace(Building.ToString(), "[A-Z]", " $0")[1..];
|
|
AttachedText.text = formatted;
|
|
|
|
AttachedButton.onClick.AddListener(OnButtonClicked);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
string formatted = Regex.Replace(Building.ToString(), "[A-Z]", " $0")[1..];
|
|
bool unlocked = UpgradeManager.Is(Building);
|
|
|
|
AttachedText.text = unlocked
|
|
? $"{formatted}\nUnlocked"
|
|
: $"{formatted}\n{Cost.AsString()}";
|
|
|
|
AttachedButton.interactable = !unlocked;
|
|
}
|
|
|
|
private void OnButtonClicked()
|
|
{
|
|
UpgradeManager.Unlock(Building);
|
|
}
|
|
}
|
|
}
|