Added building unlock buttons

This commit is contained in:
2026-04-21 21:02:06 +01:00
parent e2d198269a
commit ac1275ac76
7 changed files with 2005 additions and 25 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
using UnityEngine;
using System;
using System.Collections.Generic;
namespace Fruitomation.Game
{
public class LineDrawer : MonoBehaviour
{
[Serializable] private class LineInfo
{
public RectTransform[] Points;
}
[Header("Settings")]
[SerializeField] private Material LineMaterial;
[SerializeField] private LineInfo[] Lines;
private List<LineRenderer> Renderers = new();
private void Awake()
{
foreach (LineInfo line in Lines)
{
GameObject go = new("LineRenderer(Script Spawned)");
go.transform.SetParent(transform);
RectTransform rt = go.AddComponent<RectTransform>();
rt.anchoredPosition = new Vector2(0, 0);
LineRenderer lr = go.AddComponent<LineRenderer>();
lr.positionCount = line.Points.Length;
lr.material = LineMaterial;
lr.widthMultiplier = 0.1f;
Renderers.Add(lr);
for (int i = 0; i < line.Points.Length; i++)
{
lr.SetPosition(i, line.Points[i].position);
}
}
}
private void Update()
{
for (int i = 0; i < Lines.Length; i++)
{
LineRenderer lr = Renderers[i];
for (int j = 0; j < Lines[i].Points.Length; j++)
{
lr.SetPosition(j, Lines[i].Points[j].position);
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 899a29d695c7407fb61d921d412c55f8
timeCreated: 1776800385

View File

@@ -9,14 +9,7 @@ using PashaBibko.Pacore.Attributes;
namespace Fruitomation.UI namespace Fruitomation.UI
{ {
public class BasicUpgradeButton : MonoBehaviour public enum UpgradeState
{
[Serializable] private class LineInfo
{
public RectTransform[] LinePoints;
}
private enum UpgradeState
{ {
Unlocked, Unlocked,
Unlockable, Unlockable,
@@ -24,6 +17,13 @@ namespace Fruitomation.UI
Hidden, Hidden,
} }
public class BasicUpgradeButton : MonoBehaviour
{
[Serializable] private class LineInfo
{
public RectTransform[] LinePoints;
}
[Header("Settings")] [Header("Settings")]
[SerializeField] private BasicUpgrade Upgrade; [SerializeField] private BasicUpgrade Upgrade;
[SerializeField] private bool DrawDefaultLines; [SerializeField] private bool DrawDefaultLines;
@@ -157,7 +157,7 @@ namespace Fruitomation.UI
AttachedButton.interactable = State == UpgradeState.Unlockable; AttachedButton.interactable = State == UpgradeState.Unlockable;
// https://stackoverflow.com/questions/27040325/c-sharp-regex-to-convert-camelcase-to-sentence-case // https://stackoverflow.com/questions/27040325/c-sharp-regex-to-convert-camelcase-to-sentence-case
string formatted = Regex.Replace(Upgrade.ToString(), @"[A-Z]", " $0")[1..]; string formatted = Regex.Replace(Upgrade.ToString(), "[A-Z]", " $0")[1..];
AttachedText.text = State switch AttachedText.text = State switch
{ {
UpgradeState.Hidden => "???", UpgradeState.Hidden => "???",

View File

@@ -1,16 +0,0 @@
using UnityEngine;
public class BuildiingUnlockButton : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,31 @@
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 OnButtonClicked()
{
UpgradeManager.Unlock(Building);
}
}
}