Added lines to the buttons
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Fruitomation.Game;
|
||||
using System.Collections.Generic;
|
||||
using Fruitomation.Game;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
@@ -23,6 +24,8 @@ namespace Fruitomation.UI
|
||||
[Header("References")]
|
||||
[SerializeField] private BasicUpgradeButton[] RequiredUpgrades;
|
||||
|
||||
private (LineRenderer, BasicUpgradeButton)[] UpgradeLines;
|
||||
|
||||
private UpgradeState State = UpgradeState.Hidden;
|
||||
private Button AttachedButton;
|
||||
private Text AttachedText;
|
||||
@@ -39,6 +42,24 @@ namespace Fruitomation.UI
|
||||
|
||||
/* Stops null reference */
|
||||
RequiredUpgrades ??= Array.Empty<BasicUpgradeButton>();
|
||||
|
||||
List<(LineRenderer, BasicUpgradeButton)> lines = new();
|
||||
foreach (BasicUpgradeButton required in RequiredUpgrades)
|
||||
{
|
||||
GameObject go = new("LineRenderer(Script Spawned)");
|
||||
go.transform.SetParent(transform);
|
||||
|
||||
RectTransform rt = go.AddComponent<RectTransform>();
|
||||
rt.anchoredPosition = new Vector2();
|
||||
|
||||
LineRenderer lr = go.AddComponent<LineRenderer>();
|
||||
lr.positionCount = 2;
|
||||
lines.Add((lr, required));
|
||||
|
||||
lr.SetPosition(0, transform.position);
|
||||
lr.SetPosition(1, required.transform.position);
|
||||
}
|
||||
UpgradeLines = lines.ToArray();
|
||||
}
|
||||
|
||||
private bool IsUnlockable =>
|
||||
@@ -51,6 +72,12 @@ namespace Fruitomation.UI
|
||||
|
||||
private void Update()
|
||||
{
|
||||
foreach ((LineRenderer lr, BasicUpgradeButton button) in UpgradeLines)
|
||||
{
|
||||
lr.SetPosition(0, transform.position);
|
||||
lr.SetPosition(1, button.transform.position);
|
||||
}
|
||||
|
||||
if (UpgradeManager.Is(Upgrade))
|
||||
{
|
||||
State = UpgradeState.Unlocked;
|
||||
@@ -73,9 +100,9 @@ namespace Fruitomation.UI
|
||||
|
||||
//
|
||||
|
||||
AttachedText.text = State == UpgradeState.Hidden
|
||||
? "???"
|
||||
: $"{Upgrade.ToString()} [{UpgradeCost}]";
|
||||
AttachedText.text = //State == UpgradeState.Hidden
|
||||
//? "???"
|
||||
$"{Upgrade.ToString()} [{UpgradeCost}]";
|
||||
}
|
||||
|
||||
private bool IsUnlocked => State == UpgradeState.Unlocked;
|
||||
|
||||
Reference in New Issue
Block a user