128 lines
3.7 KiB
C#
128 lines
3.7 KiB
C#
using MEC;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BuildingCtrl : MonoBehaviour
|
|
{
|
|
public bool isProduction;
|
|
public int position;
|
|
public int wave;
|
|
public int buildingLevel;
|
|
|
|
UnitCtrl unitInfo;
|
|
|
|
Image img;
|
|
|
|
private void Start()
|
|
{
|
|
Timing.RunCoroutine(BuildingSet());
|
|
}
|
|
private IEnumerator<float> BuildingSet()
|
|
{
|
|
yield return Timing.WaitForSeconds(0.1f);
|
|
//ui재정렬
|
|
RectTransform rt = gameObject.GetComponent<RectTransform>();
|
|
RectTransform changeRt = gameObject.GetComponentsInChildren<RectTransform>()[1];
|
|
img = changeRt.GetComponent<Image>();
|
|
float sizeSet = (rt.sizeDelta.y / 2) - 10;
|
|
changeRt.offsetMin = new Vector2(-sizeSet, 10.0f);
|
|
changeRt.offsetMax = new Vector2(sizeSet, -10.0f);
|
|
}
|
|
|
|
public void Button()
|
|
{
|
|
if(isProduction || buildingLevel != 0)//생산건물 이거나 일반건물 레벨업
|
|
{
|
|
|
|
if (!isProduction)
|
|
{
|
|
int sell = 0;
|
|
for (int n = 0; n < buildingLevel; n++)
|
|
{
|
|
sell += unitInfo.unit.buy[n];
|
|
}
|
|
sell /= 3;
|
|
PlayCtrl.Instance.LevelupBuyAndSellText(unitInfo.unit.buy[buildingLevel], sell);
|
|
}
|
|
else
|
|
{
|
|
PlayCtrl.Instance.LevelupBuyAndSellText(500 * buildingLevel, 0);
|
|
}
|
|
|
|
|
|
PlayCtrl.Instance.buildingLevelupUI.SetActive(true);
|
|
PlayCtrl.Instance.newBuildingUI.SetActive(false);
|
|
PlayCtrl.Instance.backButton.SetActive(true);
|
|
}
|
|
else //신규건물 생산
|
|
{
|
|
PlayCtrl.Instance.buildingLevelupUI.SetActive(false);
|
|
PlayCtrl.Instance.newBuildingUI.SetActive(true);
|
|
PlayCtrl.Instance.backButton.SetActive(true);
|
|
}
|
|
//나의 정보를 PlayCtrl에 전달후 특정 상황이 되면 상호작용 하게 만들기
|
|
PlayCtrl.Instance.buildingCtrl = this;
|
|
}
|
|
|
|
public void LevelUp()
|
|
{
|
|
if (buildingLevel >= 5)
|
|
{
|
|
Debug.Log("건물이 최대 레벨 입니다.");
|
|
return;
|
|
}
|
|
if (!isProduction)
|
|
{
|
|
if(unitInfo.unit.buy[buildingLevel] > PlayCtrl.Instance.money)
|
|
{
|
|
Debug.Log("구매비용이 부족합니다");
|
|
if (buildingLevel == 0)
|
|
DeletBuilding();
|
|
return;
|
|
}
|
|
PlayCtrl.Instance.TextUpdate(-unitInfo.unit.buy[buildingLevel]);
|
|
PlayCtrl.Instance.player.buildings[wave].level[position - 1] = buildingLevel + 1;
|
|
} else
|
|
{
|
|
if(500 * buildingLevel > PlayCtrl.Instance.money)
|
|
{
|
|
Debug.Log("구매비용이 부족합니다");
|
|
return;
|
|
}
|
|
PlayCtrl.Instance.TextUpdate(-500 * buildingLevel);
|
|
PlayCtrl.Instance.player.addMoney[wave] += 100;
|
|
}
|
|
buildingLevel++;
|
|
}
|
|
|
|
public void DeletBuilding()
|
|
{
|
|
if (isProduction)
|
|
{
|
|
Debug.Log("생산건물은 파괴할 수 없습니다.");
|
|
return;
|
|
}
|
|
int sell = 0;
|
|
for(int n = 0; n < buildingLevel; n++)
|
|
{
|
|
sell += unitInfo.unit.buy[n];
|
|
}
|
|
sell /= 3;
|
|
PlayCtrl.Instance.TextUpdate(sell);
|
|
unitInfo = null;
|
|
img.sprite = null;
|
|
img.color = Color.clear;
|
|
buildingLevel = 0;
|
|
}
|
|
|
|
public void NewBuilding(UnitCtrl unitInfo, Sprite unitImg)
|
|
{
|
|
this.unitInfo = unitInfo;
|
|
img.sprite = unitImg;
|
|
img.color = Color.white;
|
|
PlayCtrl.Instance.player.buildings[wave].units[position - 1] = unitInfo;
|
|
LevelUp();
|
|
}
|
|
}
|