95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Buildings : MonoBehaviour
|
|
{
|
|
// Start is called before the first frame update
|
|
public int Level;
|
|
public int MaxLevel;
|
|
public List<int> upgradeNeeds_Wood;
|
|
public List<int> upgradeNeeds_Stone;
|
|
|
|
public Canvas information_Panel;
|
|
void Start()
|
|
{
|
|
Level = 1;
|
|
//StartCoroutine(Second());
|
|
InvokeRepeating("AddResources_Auto", 1, 1);
|
|
information_Panel.transform.Find("NextUpgradeNeeds").GetComponent<Text>().text = "下次升级所需物资:\n" + "木头" + upgradeNeeds_Wood[Level] + "\n" + "石头" + upgradeNeeds_Stone[Level];
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Level < MaxLevel)
|
|
{
|
|
if (Check_Upgrade())
|
|
{
|
|
information_Panel.transform.Find("Upgrade").GetComponent<Button>().interactable = true;
|
|
}
|
|
else
|
|
{
|
|
information_Panel.transform.Find("Upgrade").GetComponent<Button>().interactable = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnMouseDown()
|
|
{
|
|
AddResources_Click();
|
|
}
|
|
|
|
public bool Check_Upgrade()
|
|
{
|
|
if (Resources.Instance.wood >= upgradeNeeds_Wood[Level] && Resources.Instance.stone >= upgradeNeeds_Stone[Level])
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void Upgrade()
|
|
{
|
|
//播放升级动画
|
|
string Animation_Name = "Upgrade_" + Level;
|
|
GetComponent<Animator>().Play(Animation_Name);
|
|
|
|
//更新数值
|
|
Resources.Instance.wood -= upgradeNeeds_Wood[Level];
|
|
Resources.Instance.stone -= upgradeNeeds_Stone[Level];
|
|
Level += 1;
|
|
|
|
//更新数值UI显示
|
|
information_Panel.transform.Find("Level").GetComponent<Text>().text = "当前等级为:"+Level;
|
|
information_Panel.transform.Find("Production_Click").GetComponent<Text>().text = "每次点击产量:" + Level*5;
|
|
information_Panel.transform.Find("Production_Auto").GetComponent<Text>().text = "每秒产量:" + (Level-1);
|
|
if (Level < MaxLevel)
|
|
{
|
|
information_Panel.transform.Find("NextUpgradeNeeds").GetComponent<Text>().text = "下次升级所需物资:\n" + "木头" + upgradeNeeds_Wood[Level] + "\n" + "石头" + upgradeNeeds_Stone[Level];
|
|
}
|
|
else
|
|
{
|
|
information_Panel.transform.Find("NextUpgradeNeeds").GetComponent<Text>().text = "已达到最高等级";
|
|
}
|
|
|
|
information_Panel.transform.Find("Upgrade").GetComponent<Button>().interactable = false;
|
|
}
|
|
//-----------------------------------------------------------------------------------------------------
|
|
|
|
public virtual void AddResources_Click()
|
|
{
|
|
Debug.Log("Click");
|
|
}
|
|
public virtual void AddResources_Auto()
|
|
{
|
|
|
|
}
|
|
public IEnumerator Second()
|
|
{
|
|
AddResources_Auto();
|
|
yield return new WaitForSeconds(1);
|
|
}
|
|
}
|