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/TowerUnlockManager.cs | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 GameCode/TowerUnlockManager.cs (limited to 'GameCode/TowerUnlockManager.cs') diff --git a/GameCode/TowerUnlockManager.cs b/GameCode/TowerUnlockManager.cs new file mode 100644 index 0000000..d96b9d5 --- /dev/null +++ b/GameCode/TowerUnlockManager.cs @@ -0,0 +1,54 @@ +using System.Collections.Generic; +using UnityEngine; + +public class TowerUnlockManager : MonoBehaviour +{ + public static TowerUnlockManager instance; + + [SerializeField] + private List unlockedTowers = new List(); + + [SerializeField] + private List unlockedBuildings = new List(); + + private void Awake() + { + instance = this; + } + + private void Start() + { + DisplayButtons(); + } + + public void UnlockTower(GameObject towerUIObject, bool isTower) + { + towerUIObject.SetActive(value: true); + if (isTower) + { + unlockedTowers.Add(towerUIObject); + } + else + { + unlockedBuildings.Add(towerUIObject); + } + DisplayButtons(); + } + + private void DisplayButtons() + { + int num = 0; + int num2 = ((unlockedBuildings.Count > 0) ? 1 : 0); + foreach (GameObject unlockedTower in unlockedTowers) + { + unlockedTower.transform.localPosition = new Vector3(num * 100 - unlockedTowers.Count * 50 + 50, 100 * num2, 0f); + num++; + } + num = 0; + foreach (GameObject unlockedBuilding in unlockedBuildings) + { + unlockedBuilding.transform.localPosition = new Vector3(num * 100 - unlockedBuildings.Count * 50 + 50, 0f, 0f); + num++; + } + } +} -- cgit v1.1-26-g67d0