Added building unlock buttons
This commit is contained in:
File diff suppressed because it is too large
Load Diff
56
Assets/Scripts/Game/Buildings/LineDrawer.cs
Normal file
56
Assets/Scripts/Game/Buildings/LineDrawer.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Buildings/LineDrawer.cs.meta
Normal file
3
Assets/Scripts/Game/Buildings/LineDrawer.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 899a29d695c7407fb61d921d412c55f8
|
||||
timeCreated: 1776800385
|
||||
@@ -9,6 +9,14 @@ using PashaBibko.Pacore.Attributes;
|
||||
|
||||
namespace Fruitomation.UI
|
||||
{
|
||||
public enum UpgradeState
|
||||
{
|
||||
Unlocked,
|
||||
Unlockable,
|
||||
Viewable,
|
||||
Hidden,
|
||||
}
|
||||
|
||||
public class BasicUpgradeButton : MonoBehaviour
|
||||
{
|
||||
[Serializable] private class LineInfo
|
||||
@@ -16,14 +24,6 @@ namespace Fruitomation.UI
|
||||
public RectTransform[] LinePoints;
|
||||
}
|
||||
|
||||
private enum UpgradeState
|
||||
{
|
||||
Unlocked,
|
||||
Unlockable,
|
||||
Viewable,
|
||||
Hidden,
|
||||
}
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private BasicUpgrade Upgrade;
|
||||
[SerializeField] private bool DrawDefaultLines;
|
||||
@@ -157,7 +157,7 @@ namespace Fruitomation.UI
|
||||
AttachedButton.interactable = State == UpgradeState.Unlockable;
|
||||
|
||||
// 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
|
||||
{
|
||||
UpgradeState.Hidden => "???",
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
31
Assets/Scripts/UI/BuildingUnlockButton.cs
Normal file
31
Assets/Scripts/UI/BuildingUnlockButton.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user