using TowerDefense.Towers; using UnityEngine; using UnityEngine.UI; namespace TowerDefense.UI.HUD { /// /// Used to display infomation about a tower using Unity UI /// public class TowerInfoDisplay : MonoBehaviour { /// /// The text component for the name /// public Text towerName; /// /// The text component for the description /// public Text description; /// /// The text component for the description /// public Text dps; /// /// The text component for the level /// public Text level; /// /// The text component for the health /// public Text health; /// /// The text component for the dimensions /// public Text dimensions; /// /// The text component for the dimensions /// public Text upgradeCost; /// /// The text component for the dimensions /// public Text sellPrice; /// /// Draws the tower data on to the canvas, if the relevant text components are populated /// /// /// The tower to gain info from /// public void Show(Tower tower) { int levelOfTower = tower.currentLevel; Show(tower, levelOfTower); } /// /// Draws the tower data on to the canvas, if the relevant text components are populated /// /// The tower to gain info from /// The level of the tower public void Show(Tower tower, int levelOfTower) { if (levelOfTower >= tower.levels.Length) { return; } TowerLevel towerLevel = tower.levels[levelOfTower]; DisplayText(towerName, tower.towerName); DisplayText(description, towerLevel.description); DisplayText(dps, towerLevel.GetTowerDps().ToString("f2")); DisplayText(health, string.Format("{0}/{1}", tower.configuration.currentHealth, towerLevel.maxHealth)); DisplayText(level, (levelOfTower + 1).ToString()); DisplayText(dimensions, string.Format("{0}, {1}", tower.dimensions.x, tower.dimensions.y)); if (levelOfTower + 1 < tower.levels.Length) { DisplayText(upgradeCost, tower.levels[levelOfTower + 1].cost.ToString()); } int sellValue = tower.GetSellLevel(levelOfTower); DisplayText(sellPrice, sellValue.ToString()); } /// /// Draws the text if the text component is populated /// /// /// static void DisplayText(Text textBox, string text) { if (textBox != null) { textBox.text = text; } } } }