82 lines
2.2 KiB
C#
82 lines
2.2 KiB
C#
using MEC;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BuildingCtrl : MonoBehaviour
|
|
{
|
|
public bool isProduction;
|
|
public int lineCount;
|
|
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)//생산건물 이거나 일반건물 레벨업
|
|
{
|
|
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;
|
|
}
|
|
PlayCtrl.Instance.player.buildings[lineCount].units.Add(unitInfo);
|
|
buildingLevel++;
|
|
}
|
|
|
|
public void DeletBuilding()
|
|
{
|
|
if (isProduction)
|
|
{
|
|
Debug.Log("생산건물은 파괴할 수 없습니다.");
|
|
return;
|
|
}
|
|
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;
|
|
LevelUp();
|
|
}
|
|
}
|