you really gotta calm down, marisa...
This commit is contained in:
parent
13bb58ea03
commit
b9fb490dce
68 changed files with 990 additions and 44 deletions
76
Assets/Scripts/Abilities/AbilityManager.cs
Normal file
76
Assets/Scripts/Abilities/AbilityManager.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue