62 lines
1.6 KiB
C#
62 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
|
|
public class Building : MonoBehaviour
|
|
{
|
|
public BuildingData buildingData;
|
|
public int curLevel;
|
|
public Outline[] outlines;
|
|
|
|
void Awake(){
|
|
//if(outline == null){outline = GetComponent<Outline>();}
|
|
outlines = GetComponentsInChildren<Outline>();
|
|
ToggleOutlines(false);
|
|
Selector.OnSelectedChanged.AddListener(OnSelectedChanged);
|
|
}
|
|
|
|
void OnSelectedChanged(){
|
|
if(Selector.selectedBuilding == null){ToggleOutlines(false); return;}
|
|
|
|
ToggleOutlines(Selector.selectedBuilding == this);
|
|
}
|
|
|
|
void ToggleOutlines(bool value){
|
|
foreach(Outline outline in outlines){
|
|
outline.enabled = value;
|
|
}
|
|
}
|
|
|
|
public async Task Upgrade(){
|
|
if(curLevel >= buildingData.levels.Count-1){Debug.Log("Already max");return;}
|
|
int cost = buildingData.levels[curLevel+1].price;
|
|
// Debug.Log("Upgrading " + buildingData.buildingName + " for " + cost + " coins");
|
|
|
|
switch (curLevel)
|
|
{
|
|
case 0: Debug.Log("1 Star"); break;
|
|
case 1: Debug.Log("2 Stars"); break;
|
|
}
|
|
|
|
|
|
await (DBmanager.SetCoins(DBmanager.Coins-cost));
|
|
Mathf.Clamp(curLevel++,0, buildingData.levels.Count-1);
|
|
|
|
await DBmanager.UpgradeBuilding(buildingData.buildingName, curLevel);
|
|
}
|
|
|
|
/* */
|
|
}
|
|
|
|
|
|
[System.Serializable]
|
|
public class BuildingState{
|
|
public string id;
|
|
public int level;
|
|
|
|
public BuildingState(string m_id, int m_level){
|
|
id = m_id;
|
|
level = m_level;
|
|
}
|
|
} |