From 3fb2121cc0d00cbd42b2ca10b5dfb399a4df1a04 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 21 Mar 2024 10:28:46 +0800 Subject: *misc --- GameCode/UpgradeManager.cs | 120 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 GameCode/UpgradeManager.cs (limited to 'GameCode/UpgradeManager.cs') diff --git a/GameCode/UpgradeManager.cs b/GameCode/UpgradeManager.cs new file mode 100644 index 0000000..685308e --- /dev/null +++ b/GameCode/UpgradeManager.cs @@ -0,0 +1,120 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class UpgradeManager : MonoBehaviour +{ + public static UpgradeManager instance; + + public int xp; + + public int prestige; + + [SerializeField] + private Text xpText; + + [SerializeField] + private GameObject prestigeDisplay; + + [SerializeField] + private Text prestigeText; + + public int unlockedCardCount; + + [SerializeField] + private UpgradeButton[] allButtons; + + [SerializeField] + private List cardsWhichRequireCardCount = new List(); + + private void Awake() + { + instance = this; + } + + private void Start() + { + allButtons = Object.FindObjectsOfType(); + UpgradeButton[] array = allButtons; + foreach (UpgradeButton upgradeButton in array) + { + if (upgradeButton.cardCountRequirement > 0) + { + cardsWhichRequireCardCount.Add(upgradeButton); + } + } + unlockedCardCount = PlayerPrefs.GetInt("UnlockedCardCount", 0); + xp = PlayerPrefs.GetInt("XP", 0); + xpText.text = "XP: " + xp; + prestige = PlayerPrefs.GetInt("Prestige", 0); + if (prestige > 0) + { + prestigeDisplay.SetActive(value: true); + prestigeText.text = "Prestige: " + prestige; + } + } + + public void AddXP(int change) + { + xp += change; + PlayerPrefs.SetInt("XP", xp); + xpText.text = "XP: " + xp; + } + + public void ResetUpgrades() + { + int num = 0; + UpgradeButton[] array = allButtons; + foreach (UpgradeButton upgradeButton in array) + { + if (upgradeButton.enabled) + { + if (upgradeButton.unlocked) + { + num += upgradeButton.xpCost; + } + upgradeButton.ResetUnlock(); + } + } + num += xp / 2; + Debug.Log("Refunded xp: " + num); + PlayerPrefs.SetInt("Prestige", prestige + num / 1000); + xp = 0; + PlayerPrefs.SetInt("XP", 0); + PlayerPrefs.SetInt("UnlockedCardCount", 0); + PlayerPrefs.SetInt("Development", 0); + PlayerPrefs.SetInt("Record1", 0); + PlayerPrefs.SetInt("Record2", 0); + PlayerPrefs.SetInt("Record3", 0); + LevelLoader.instance.LoadLevel("MainMenu"); + } + + public void CountCard(bool countsAsCardUnlock) + { + if (countsAsCardUnlock) + { + unlockedCardCount++; + Debug.Log("Number of unlocked cards: " + unlockedCardCount); + PlayerPrefs.SetInt("UnlockedCardCount", unlockedCardCount); + CheckCardCount(); + } + } + + public void CountDevelopment(bool value) + { + if (value) + { + int @int = PlayerPrefs.GetInt("Development", 0); + PlayerPrefs.SetInt("Development", @int + 1); + Debug.Log("Development: " + (@int + 1)); + } + } + + public void CheckCardCount() + { + foreach (UpgradeButton item in cardsWhichRequireCardCount) + { + item.CheckEnabled(); + } + } +} -- cgit v1.1-26-g67d0