wangguan
2020-12-16 fe59d1a97e80284315bcdfa18a49059b38dfd137
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using KTGMGemClient;
using TowerDefense.Towers;
using UnityEngine;
using UnityEngine.UI;
 
namespace TowerDefense.UI.HUD
{
    /// <summary>
    /// Used to display infomation about a tower using Unity UI
    /// </summary>
    public class TowerInfoDisplay : MonoBehaviour
    {
        /// <summary>
        /// The text component for the name
        /// </summary>
        public Text towerName;
 
        /// <summary>
        /// The text component for the description
        /// </summary>
        public Text description;
 
        /// <summary>
        /// The text component for the description
        /// </summary>
        public Text dps;
 
        /// <summary>
        /// The text component for the level
        /// </summary>
        public Text level;
 
        /// <summary>
        /// The text component for the health
        /// </summary>
        public Text health;
 
        /// <summary>
        /// The text component for the dimensions
        /// </summary>
        public Text dimensions;
 
        /// <summary>
        /// The text component for the dimensions
        /// </summary>
        public Text upgradeCost;
 
        /// <summary>
        /// The text component for the dimensions
        /// </summary>
        public Text sellPrice;
 
        /// <summary>
        /// Draws the tower data on to the canvas, if the relevant text components are populated
        /// </summary>
        /// <param name="tower">
        /// The tower to gain info from
        /// </param>
        public void Show(Tower tower)
        {
            int levelOfTower = tower.currentLevel;
            Show(tower, levelOfTower);
        }
 
        /// <summary>
        /// Draws the tower data on to the canvas, if the relevant text components are populated
        /// </summary>
        /// <param name="tower">The tower to gain info from</param>
        /// <param name="levelOfTower">The level of the tower</param>
        public void Show(Tower tower, int levelOfTower)
        {
            if (levelOfTower >= ElfUpgradeData.MaxTowerLevel)
            {
                return;
            }
            TowerLevel towerLevel = tower.CurrentTowerLevel;
            DisplayText(towerName, tower.towerName);
            DisplayText(level, (levelOfTower + 1).ToString());
            DisplayText(dimensions, string.Format("{0}, {1}", tower.dimensions.x, tower.dimensions.y));
        }
 
        /// <summary>
        /// Draws the text if the text component is populated
        /// </summary>
        /// <param name="textBox"></param>
        /// <param name="text"></param>
        static void DisplayText(Text textBox, string text)
        {
            if (textBox != null)
            {
                textBox.text = text;
            }
        }
    }
}