five hundred million if statements
This commit is contained in:
parent
9930aba85d
commit
24ab1b213e
5 changed files with 203 additions and 44 deletions
|
|
@ -26,6 +26,7 @@ public class AbilityManager : MonoBehaviour
|
|||
public Button upgradeButton;
|
||||
[Header("Upgrades")]
|
||||
public AbilityUpgrade[] allUpgrades;
|
||||
public PlayerAbility[] allAbilities;
|
||||
public Dictionary<AbilityUpgrade, int> upgradesInventory = new();
|
||||
private void Start()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -54,14 +54,14 @@ public class AbilityUIHandler : MonoBehaviour
|
|||
|
||||
public void UpdateAbilitySelection()
|
||||
{
|
||||
uiObjects[0].onClick.AddListener(() => ShowAbilityUI(playerAbilityHandler.mainAttackInstance));
|
||||
uiObjects[0].GetComponentInChildren<TextMeshProUGUI>().text = playerAbilityHandler.mainAttackInstance.abilityName;
|
||||
uiObjects[1].onClick.AddListener(() => ShowAbilityUI(playerAbilityHandler.secondaryAttackInstance));
|
||||
uiObjects[1].GetComponentInChildren<TextMeshProUGUI>().text = playerAbilityHandler.secondaryAttackInstance.abilityName;
|
||||
uiObjects[2].onClick.AddListener(() => ShowAbilityUI(playerAbilityHandler.spellAInstance));
|
||||
uiObjects[2].GetComponentInChildren<TextMeshProUGUI>().text = playerAbilityHandler.spellAInstance.abilityName;
|
||||
uiObjects[3].onClick.AddListener(() => ShowAbilityUI(playerAbilityHandler.spellBInstance));
|
||||
uiObjects[3].GetComponentInChildren<TextMeshProUGUI>().text = playerAbilityHandler.spellBInstance.abilityName;
|
||||
int currentUIObject = 0;
|
||||
foreach (Button uiObject in uiObjects)
|
||||
{
|
||||
var o = currentUIObject;
|
||||
uiObject.onClick.AddListener(() => ShowAbilityUI(playerAbilityHandler.abilityInstances[o]));
|
||||
uiObject.GetComponentInChildren<TextMeshProUGUI>().text = playerAbilityHandler.abilityInstances[o].abilityName;
|
||||
currentUIObject++;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowAbilityUI(PlayerAbility ability)
|
||||
|
|
|
|||
|
|
@ -22,15 +22,80 @@ public class AbilitySceneTransfer : MonoBehaviour
|
|||
[System.Serializable]
|
||||
public class SavedAbility
|
||||
{
|
||||
public enum AbilitySlot {Primary, Secondary, SpellA, SpellB}
|
||||
public AbilitySlot abilitySlot = AbilitySlot.Primary;
|
||||
public string abilityName;
|
||||
public Dictionary<string, int> equippedUpgrades;
|
||||
public Dictionary<string, int> equippedUpgrades = new();
|
||||
}
|
||||
public List<SavedAbility> savedAbilities;
|
||||
public MarisaAbilityHandler abilityHandler;
|
||||
|
||||
[ContextMenu("Save")]
|
||||
public void TestSaving()
|
||||
{
|
||||
int testSlot = 0;
|
||||
foreach (PlayerAbility ability in abilityHandler.abilityInstances)
|
||||
{
|
||||
SaveAbility(ability);
|
||||
savedAbilities[testSlot].abilitySlot = (SavedAbility.AbilitySlot)testSlot;
|
||||
testSlot++;
|
||||
}
|
||||
}
|
||||
[ContextMenu("Load")]
|
||||
public void TestLoading()
|
||||
{
|
||||
LoadAbilities();
|
||||
}
|
||||
public void SaveAbility(PlayerAbility savedAbility)
|
||||
{
|
||||
savedAbilities.Add(new SavedAbility
|
||||
SavedAbility newSavedAbility = new();
|
||||
newSavedAbility.abilityName = savedAbility.abilityName;
|
||||
foreach (AbilityUpgrade upgrade in AbilityManager.instance.allUpgrades)
|
||||
{
|
||||
abilityName = savedAbility.abilityName
|
||||
});
|
||||
int upgradeCount = savedAbility.GetUpgradeCount(upgrade);
|
||||
if (upgradeCount > 0)
|
||||
{
|
||||
newSavedAbility.equippedUpgrades[upgrade.upgradeName] = upgradeCount;
|
||||
}
|
||||
}
|
||||
savedAbilities.Add(newSavedAbility);
|
||||
}
|
||||
|
||||
public void LoadAbilities()
|
||||
{
|
||||
abilityHandler.abilities.Clear();
|
||||
foreach (SavedAbility savedAbility in savedAbilities)
|
||||
{
|
||||
PlayerAbility foundAbility = null;
|
||||
foreach (PlayerAbility ability in AbilityManager.instance.allAbilities)
|
||||
{
|
||||
if (savedAbility.abilityName == ability.abilityName) //shit code
|
||||
{
|
||||
foundAbility = ability;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundAbility)
|
||||
{
|
||||
Debug.LogWarning($"{savedAbility.abilityName} was not found.");
|
||||
}
|
||||
switch (savedAbility.abilitySlot)
|
||||
{
|
||||
case SavedAbility.AbilitySlot.Primary :
|
||||
abilityHandler.abilities[0] = foundAbility;
|
||||
break;
|
||||
case SavedAbility.AbilitySlot.Secondary :
|
||||
abilityHandler.abilities[1] = foundAbility;
|
||||
break;
|
||||
case SavedAbility.AbilitySlot.SpellA :
|
||||
abilityHandler.abilities[2] = foundAbility;
|
||||
break;
|
||||
case SavedAbility.AbilitySlot.SpellB :
|
||||
abilityHandler.abilities[3] = foundAbility;
|
||||
break;
|
||||
}
|
||||
}
|
||||
abilityHandler.SetupAbilities();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
|
|
@ -6,62 +7,62 @@ public class MarisaAbilityHandler : MonoBehaviour
|
|||
{
|
||||
[SerializeField] private PlayerInput inputHandler;
|
||||
[SerializeField] private Marisa thisPlayer;
|
||||
|
||||
[Header("Abilities")] //maybe have to make them public for when you're changing out abilities
|
||||
[SerializeField] private PlayerAbility mainAttack;
|
||||
[SerializeField] private PlayerAbility secondaryAttack;
|
||||
[SerializeField] private PlayerAbility spellA;
|
||||
[SerializeField] private PlayerAbility spellB;
|
||||
public List<PlayerAbility> abilities = new();
|
||||
|
||||
[Header("Ability Instances")]
|
||||
public PlayerAbility mainAttackInstance;
|
||||
public PlayerAbility secondaryAttackInstance;
|
||||
public PlayerAbility spellAInstance;
|
||||
public PlayerAbility spellBInstance;
|
||||
public List<PlayerAbility> abilityInstances = new();
|
||||
|
||||
[Header("UI")]
|
||||
public AbilityHotbarIcon mainIcon;
|
||||
public AbilityHotbarIcon secondaryIcon;
|
||||
public AbilityHotbarIcon spellAIcon;
|
||||
public AbilityHotbarIcon spellBIcon;
|
||||
public AbilityHotbarIcon[] hotbarIcons;
|
||||
//this is getting ridiculous
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
mainAttackInstance = Instantiate(mainAttack, transform);
|
||||
mainAttackInstance.thisPlayer = thisPlayer;
|
||||
mainIcon.UpdateAbility(mainAttackInstance);
|
||||
secondaryAttackInstance = Instantiate(secondaryAttack, transform);
|
||||
secondaryAttackInstance.thisPlayer = thisPlayer;
|
||||
secondaryIcon.UpdateAbility(secondaryAttackInstance);
|
||||
spellAInstance = Instantiate(spellA, transform);
|
||||
spellAInstance.thisPlayer = thisPlayer;
|
||||
spellAIcon.UpdateAbility(spellAInstance);
|
||||
spellBInstance = Instantiate(spellB, transform);
|
||||
spellBInstance.thisPlayer = thisPlayer;
|
||||
spellBIcon.UpdateAbility(spellBInstance);
|
||||
SetupAbilities();
|
||||
}
|
||||
|
||||
public void SetupAbilities()
|
||||
{
|
||||
foreach (PlayerAbility oldAbility in abilityInstances)
|
||||
{
|
||||
Destroy(oldAbility.gameObject);
|
||||
}
|
||||
abilityInstances.Clear();
|
||||
int currentAbilityCount = 0;
|
||||
foreach (PlayerAbility ability in abilities)
|
||||
{
|
||||
PlayerAbility newAbility = Instantiate(ability, transform);
|
||||
abilityInstances.Add(newAbility);
|
||||
newAbility.thisPlayer = thisPlayer;
|
||||
hotbarIcons[currentAbilityCount].UpdateAbility(newAbility);
|
||||
currentAbilityCount++;
|
||||
Debug.Log(ability.abilityName);
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (inputHandler.actions["MainAttack"].inProgress)
|
||||
{
|
||||
mainAttackInstance.TryAbility();
|
||||
mainIcon.UpdateCooldown();
|
||||
abilityInstances[0].TryAbility();
|
||||
hotbarIcons[0].UpdateCooldown();
|
||||
}
|
||||
else if (inputHandler.actions["SecondaryAttack"].inProgress)
|
||||
{
|
||||
secondaryAttackInstance.TryAbility();
|
||||
secondaryIcon.UpdateCooldown();
|
||||
abilityInstances[1].TryAbility();
|
||||
hotbarIcons[1].UpdateCooldown();
|
||||
}
|
||||
else if (inputHandler.actions["SpellA"].inProgress)
|
||||
{
|
||||
spellAInstance.TryAbility();
|
||||
spellAIcon.UpdateCooldown();
|
||||
abilityInstances[2].TryAbility();
|
||||
hotbarIcons[2].UpdateCooldown();
|
||||
}
|
||||
else if (inputHandler.actions["SpellB"].inProgress)
|
||||
{
|
||||
spellBInstance.TryAbility();
|
||||
spellBIcon.UpdateCooldown();
|
||||
abilityInstances[3].TryAbility();
|
||||
hotbarIcons[3].UpdateCooldown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue