76 lines
2 KiB
C#
76 lines
2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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 class StoredUpgrade
|
|
{
|
|
public AbilityUpgrade upgrade;
|
|
public int count;
|
|
}
|
|
public MarisaAbilityHandler player;
|
|
public AbilityUpgrade upgradeToAdd;
|
|
public Button upgradeButton;
|
|
|
|
[Header("Upgrades")]
|
|
public List<StoredUpgrade> upgradesInventory;
|
|
private void Start()
|
|
{
|
|
upgradeButton.onClick.AddListener((() => AddUpgrade(upgradeToAdd, player.mainAttackInstance)));
|
|
}
|
|
|
|
public void AddUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
|
{
|
|
if (!ability.attachedUpgrades.Contains(upgrade))
|
|
{
|
|
AbilityUpgrade newUpgrade = Instantiate(upgrade, ability.transform);
|
|
ability.attachedUpgrades.Add(newUpgrade);
|
|
newUpgrade.thisPlayerAbility = ability;
|
|
newUpgrade.ApplyUpgrade();
|
|
}
|
|
else
|
|
{
|
|
ability.attachedUpgrades.TryGetValue(upgrade, out AbilityUpgrade foundUpgrade);
|
|
if (foundUpgrade)
|
|
{
|
|
foundUpgrade.count++;
|
|
foundUpgrade.ApplyUpgrade();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RemoveUpgrade(AbilityUpgrade upgrade, PlayerAbility ability)
|
|
{
|
|
if (ability.attachedUpgrades.TryGetValue(upgrade, out AbilityUpgrade foundUpgrade))
|
|
{
|
|
if (foundUpgrade.count > 1)
|
|
{
|
|
foundUpgrade.ApplyRemoval();
|
|
foundUpgrade.count--;
|
|
}
|
|
else
|
|
{
|
|
foundUpgrade.ApplyRemoval();
|
|
ability.attachedUpgrades.Remove(foundUpgrade);
|
|
}
|
|
}
|
|
}
|
|
}
|