//using Boo.Lang;
using TowerDefense.Level;
using TowerDefense.Towers;
using UnityEngine;
using UnityEngine.UI;
namespace TowerDefense.UI.HUD
{
///
/// Controls the UI objects that draw the tower data
///
[RequireComponent(typeof(Canvas))]
public class TowerUI : MonoBehaviour
{
///
/// The text object for the name
///
public Text towerName;
///
/// The text object for the description
///
public Text description;
public Text upgradeDescription;
///
/// The attached sell button
///
public Button sellButton;
///
/// The attached upgrade button
///
public Button upgradeButton;
///
/// Component to display the relevant information of the tower
///
public TowerInfoDisplay towerInfoDisplay;
public RectTransform panelRectTransform;
public GameObject[] confirmationButtons;
///
/// The main game camera
///
protected Camera m_GameCamera;
///
/// The current tower to draw
///
protected Tower m_Tower;
///
/// The canvas attached to the gameObject
///
protected Canvas m_Canvas;
///
/// Draws the tower data on to the canvas,在界面上显示塔防信息,显示操作和信息界面。
/// 继续修改,确保其它方面的内容处理。
///
///
/// The tower to gain info from
///
public virtual void Show(Tower towerToShow)
{
if (towerToShow == null)
{
return;
}
m_Tower = towerToShow;
AdjustPosition();
// TEST COED TO DELETE:
if (sellButton != null)
{
// TEST CODE TO DELETE:
if (m_Tower != null)
GameUI.instance.startDragTower(m_Tower);
return;
}
else
{
if (GameUI.instance.towerInList(m_Tower))
return;
}
m_Canvas.enabled = true;
if (upgradeButton != null)
{
upgradeButton.interactable = true;
bool maxLevel = m_Tower.IsMaxLevel;
upgradeButton.gameObject.SetActive(!maxLevel);
}
LevelManager.instance.currency.currencyChanged += OnCurrencyChanged;
towerInfoDisplay.Show(towerToShow);
foreach (var button in confirmationButtons)
{
button.SetActive(false);
}
}
///
/// Hides the tower info UI and the radius visualizer
///
public virtual void Hide()
{
m_Tower = null;
if (GameUI.instanceExists)
{
GameUI.instance.HideRadiusVisualizer();
}
m_Canvas.enabled = false;
LevelManager.instance.currency.currencyChanged -= OnCurrencyChanged;
}
///
/// Upgrades the tower through
///
public void UpgradeButtonClick()
{
GameUI.instance.UpgradeSelectedTower();
}
///
/// Sells the tower through
///
public void SellButtonClick()
{
GameUI.instance.SellSelectedTower();
}
///
/// Get the text attached to the buttons
///
protected virtual void Awake()
{
m_Canvas = GetComponent