using UnityEngine.UI; using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class SelectedItemMenu : MonoBehaviour { public Text nameTxt; public Button upgradeBtn; public Button infoBtn; [Header("info menu")] public GameObject infoMenu; public TMP_Text descriptionTxt; [Header("upgrade menu")] public GameObject upgradeMenu; public Transform upgrade_statParent; public Transform price_statParent; void Start() { Selector.OnSelectedChanged.AddListener(OnSelectionChanged); upgradeBtn.onClick.AddListener(OnUpgradeClicked); infoBtn.onClick.AddListener(OnInfoClicked); } void OnSelectionChanged() { if (Selector.selectedBuilding != null) { infoBtn.gameObject.SetActive(true); if (Selector.selectedBuilding.buildingData.levels.Count <= 1) { upgradeBtn.gameObject.SetActive(false); } else { upgradeBtn.gameObject.SetActive(true); } } else { upgradeBtn.gameObject.SetActive(false); infoBtn.gameObject.SetActive(false); } } void OnUpgradeClicked() { Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name); upgradeMenu.SetActive(true); List stats = Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel].stats; for (int i = 0; i < upgrade_statParent.childCount; i++) { bool hasDataForThis = i < stats.Count; upgrade_statParent.GetChild(i).gameObject.SetActive(hasDataForThis); if (hasDataForThis) { upgrade_statParent.GetChild(i).GetChild(0).GetComponent().text = stats[i].name; upgrade_statParent.GetChild(i).GetChild(1).GetComponent().text = stats[i].value; // price_statParent.GetChild(1).GetComponent().text = stats[i].price; Debug.Log(price_statParent); } } if (upgrade_statParent.childCount > stats.Count) { Debug.LogError("Please add another slot for stats in upgrade menu.\nSlots not enough for " + Selector.selectedBuilding.buildingData.name + " , " + upgrade_statParent.childCount + " slots for " + stats.Count + " stats"); } } void OnInfoClicked() { Debug.Log("Opening Info Menu for : " + Selector.selectedBuilding.buildingData.name); infoMenu.SetActive(true); descriptionTxt.text = Selector.selectedBuilding.buildingData.description; } }