97 lines
2 KiB
C#
97 lines
2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class ShopManager : MonoBehaviour
|
|
{
|
|
#region Statication
|
|
|
|
public static ShopManager instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
DontDestroyOnLoad(this);
|
|
}
|
|
|
|
#endregion
|
|
public List<AbilityUpgrade> buyableUpgrades;
|
|
[SerializeField] private int maxBuyables;
|
|
public int currency; //uh. we need to figure out this one lol
|
|
public GameObject shopUIObject;
|
|
[SerializeField] private Marisa player;
|
|
[Header("UI")]
|
|
public Transform upgradeListUI;
|
|
public Button templateUpgradeButton;
|
|
|
|
private void Start()
|
|
{
|
|
GenerateUpgradeList();
|
|
}
|
|
|
|
public void GenerateUpgradeList()
|
|
{
|
|
foreach (AbilityUpgrade upgrade in buyableUpgrades)
|
|
{
|
|
Button newButton = Instantiate(templateUpgradeButton, upgradeListUI);
|
|
newButton.onClick.AddListener(() => BuyUpgrade(upgrade));
|
|
}
|
|
}
|
|
|
|
public void BuyUpgrade(AbilityUpgrade abilityToBuy)
|
|
{
|
|
if (currency >= abilityToBuy.cost)
|
|
{
|
|
AbilityManager.instance.upgradesInventory[abilityToBuy]++;
|
|
currency -= abilityToBuy.cost;
|
|
}
|
|
|
|
}
|
|
|
|
public void SellUpgrade(AbilityUpgrade abilityToSell)
|
|
{
|
|
AbilityManager.instance.upgradesInventory[abilityToSell]--;
|
|
currency += abilityToSell.cost/2;
|
|
}
|
|
|
|
public void OpenShopUI()
|
|
{
|
|
shopUIObject.SetActive(true);
|
|
player.stalled = true;
|
|
}
|
|
|
|
public void CloseShopUI()
|
|
{
|
|
shopUIObject.SetActive(false);
|
|
player.stalled = false;
|
|
}
|
|
|
|
public void UpgradesMenu()
|
|
{
|
|
|
|
}
|
|
|
|
public void SellMenu()
|
|
{
|
|
|
|
}
|
|
|
|
public void TalkMenu()
|
|
{
|
|
|
|
}
|
|
|
|
private void ClearInventoryUI()
|
|
{
|
|
foreach (Transform child in upgradeListUI)
|
|
{
|
|
Destroy(child);
|
|
}
|
|
}
|
|
}
|