76 lines
2 KiB
C#
76 lines
2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AbilityManager : MonoBehaviour
|
|
{
|
|
#region Statication
|
|
|
|
public static AbilityManager instance;
|
|
|
|
private void Awake()
|
|
{
|
|
if (instance != null && instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
instance = this;
|
|
}
|
|
|
|
#endregion
|
|
public MarisaAbilityHandler player;
|
|
public AbilityUpgrade upgradeToAdd;
|
|
public Button upgradeButton;
|
|
[Header("Upgrades")]
|
|
public AbilityUpgrade[] allUpgrades;
|
|
public Dictionary<AbilityUpgrade, int> upgradesInventory = new();
|
|
private void Start()
|
|
{
|
|
// upgradeButton.onClick.AddListener((() => AddUpgrade(upgradeToAdd, player.mainAttackInstance)));
|
|
StoreUpgrade(upgradeToAdd);
|
|
}
|
|
|
|
public void StoreUpgrade(AbilityUpgrade upgradeToStore)
|
|
{
|
|
if (!upgradesInventory.ContainsKey(upgradeToStore))
|
|
{
|
|
upgradesInventory[upgradeToStore] = 0;
|
|
}
|
|
upgradesInventory[upgradeToStore]++;
|
|
Debug.Log($"Added upgrade {upgradeToStore.upgradeName}. Current count: {upgradesInventory[upgradeToStore]}");
|
|
AbilityUIHandler.instance.UpdateInventory();
|
|
}
|
|
|
|
public int GetUpgradeCount(AbilityUpgrade upgrade)
|
|
{
|
|
if (!upgradesInventory.ContainsKey(upgrade))
|
|
{
|
|
return 0;
|
|
}
|
|
return upgradesInventory[upgrade];
|
|
}
|
|
public void AddUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
|
{
|
|
if (upgradesInventory.ContainsKey(upgrade))
|
|
{
|
|
upgradesInventory[upgrade]--;
|
|
if (upgradesInventory[upgrade] <= 0)
|
|
{
|
|
upgradesInventory.Remove(upgrade);
|
|
}
|
|
ability.AddUpgrade(upgrade);
|
|
AbilityUIHandler.instance.UpdateInventory();
|
|
}
|
|
}
|
|
|
|
public void RemoveUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
|
{
|
|
if (ability.RemoveUpgrade(upgrade))
|
|
{
|
|
StoreUpgrade(upgrade);
|
|
}
|
|
}
|
|
}
|