Building upgradable

This commit is contained in:
Sewmina
2022-04-12 02:53:06 +05:30
parent bc0601ecf8
commit c6a8c5c7f3
38 changed files with 2082 additions and 2623 deletions

View File

@@ -1561,7 +1561,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 417.81, y: 0}
m_SizeDelta: {x: 0, y: 90}
m_Pivot: {x: 1, y: 0.5}
--- !u!114 &16466549
@@ -125056,13 +125056,13 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
nameTxt: {fileID: 1480392899}
upgradeBtn: {fileID: 770020523}
upgradeMenuBtn: {fileID: 770020523}
infoBtn: {fileID: 386684403}
infoMenu: {fileID: 1994277184}
descriptionTxt: {fileID: 503357262}
upgradeMenu: {fileID: 381659749}
upgrade_statParent: {fileID: 1524033405}
price_statParent: {fileID: 114207908}
upgradeBtn: {fileID: 1648598145}
--- !u!4 &1259898503 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 4322694313257492, guid: 5b7c91a625e35744c9263b8194bb306c, type: 3}
@@ -186189,7 +186189,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchoredPosition: {x: 788.45, y: 0}
m_SizeDelta: {x: 0, y: 90}
m_Pivot: {x: 1, y: 0.5}
--- !u!114 &1934658493

View File

@@ -22,6 +22,7 @@ MonoBehaviour:
value: 2
- name: Energy
value: 50
price: 1000
- level: 2
stats:
- name: Stat 1
@@ -30,4 +31,5 @@ MonoBehaviour:
value: 30
- name: Energy
value: 500
price: 15000
description: This is the Hall (Main Hall)

View File

@@ -22,6 +22,7 @@ MonoBehaviour:
value: 50
- name: Something else
value: 40 %
price: 0
- level: 2
stats:
- name: Power
@@ -30,4 +31,5 @@ MonoBehaviour:
value: 90
- name: Something else
value: 80 %
price: 15000
description: This is a Research Lab

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class Building : MonoBehaviour
@@ -18,8 +19,7 @@ public class Building : MonoBehaviour
void OnSelectedChanged(){
if(Selector.selectedBuilding == null){ToggleOutlines(false); return;}
ToggleOutlines(Selector.selectedBuilding == this);
// Debug.Log(buildingName);
ToggleOutlines(Selector.selectedBuilding == this);
}
void ToggleOutlines(bool value){
@@ -28,5 +28,14 @@ public class Building : MonoBehaviour
}
}
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");
await (DBmanager.SetCoins(DBmanager.Coins-cost));
Mathf.Clamp(curLevel++,0, buildingData.levels.Count-1);
}
/* */
}

View File

@@ -7,7 +7,7 @@ public class BuildingData : ScriptableObject
public string buildingName;
public List<BuildingLevel> levels = new List<BuildingLevel>{
new BuildingLevel(1,new List<BuildingStat>())
new BuildingLevel(1,new List<BuildingStat>(), 1000)
};
public string description;
@@ -30,13 +30,12 @@ public class BuildingStat{
public class BuildingLevel{
public int level = 0;
public List<BuildingStat> stats;
public int price = 1000;
public BuildingLevel(int _level, List<BuildingStat> _stats){
public BuildingLevel(int _level, List<BuildingStat> _stats, int _price){
level = _level;
stats = _stats;
price = _price;
}
}

View File

@@ -21,7 +21,7 @@ public class DBmanager : MonoBehaviour
username = null;
}
public async static void SetCoins(int newValue, bool justOffline = false){
public async static Task SetCoins(int newValue, bool justOffline = false){
WWWForm form = new WWWForm();
form.AddField("name", username);
form.AddField("coins", newValue);

View File

@@ -6,7 +6,7 @@ using TMPro;
public class SelectedItemMenu : MonoBehaviour
{
public Text nameTxt;
public Button upgradeBtn;
public Button upgradeMenuBtn;
public Button infoBtn;
[Header("info menu")]
@@ -16,14 +16,14 @@ public class SelectedItemMenu : MonoBehaviour
[Header("upgrade menu")]
public GameObject upgradeMenu;
public Transform upgrade_statParent;
public Transform price_statParent;
public Button upgradeBtn;
void Start()
{
Selector.OnSelectedChanged.AddListener(OnSelectionChanged);
upgradeBtn.onClick.AddListener(OnUpgradeClicked);
upgradeMenuBtn.onClick.AddListener(OnUpgradeMenuClicked);
infoBtn.onClick.AddListener(OnInfoClicked);
upgradeBtn.onClick.AddListener(OnUpgrade);
}
void OnSelectionChanged()
@@ -31,27 +31,45 @@ public class SelectedItemMenu : MonoBehaviour
if (Selector.selectedBuilding != null)
{
infoBtn.gameObject.SetActive(true);
if (Selector.selectedBuilding.buildingData.levels.Count <= 1)
if (Selector.selectedData.levels.Count <= 1)
{
upgradeBtn.gameObject.SetActive(false);
upgradeMenuBtn.gameObject.SetActive(false);
}
else
{
upgradeBtn.gameObject.SetActive(true);
upgradeMenuBtn.gameObject.SetActive(true);
}
}
else
{
upgradeBtn.gameObject.SetActive(false);
upgradeMenuBtn.gameObject.SetActive(false);
infoBtn.gameObject.SetActive(false);
}
upgradeMenu.SetActive(false);
infoMenu.SetActive(false);
}
void OnUpgradeClicked()
void OnUpgradeMenuClicked()
{
Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name);
upgradeMenu.SetActive(true);
if (Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count - 1)
{
upgradeBtn.interactable = (Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price < DBmanager.Coins);
upgradeBtn.GetComponentInChildren<TMP_Text>().text = Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price.ToString();
}
else
{
upgradeBtn.interactable = false;
upgradeBtn.GetComponentInChildren<TMP_Text>().text = "MAX!";
Debug.Log("Already max");
}
List<BuildingStat> stats = Selector.selectedBuilding.buildingData.levels[Selector.selectedBuilding.curLevel].stats;
for (int i = 0; i < upgrade_statParent.childCount; i++)
{
@@ -61,17 +79,21 @@ public class SelectedItemMenu : MonoBehaviour
{
upgrade_statParent.GetChild(i).GetChild(0).GetComponent<TMP_Text>().text = stats[i].name;
upgrade_statParent.GetChild(i).GetChild(1).GetComponent<TMP_Text>().text = stats[i].value;
// price_statParent.GetChild(1).GetComponent<TMP_Text>().text = stats[i].price;
Debug.Log(price_statParent);
}
}
if (upgrade_statParent.childCount > stats.Count)
{
Debug.LogError("Please add another slot for stats in upgrade menu.\nSlots not enough for " + Selector.selectedBuilding.buildingData.name + " , " + upgrade_statParent.childCount + " slots for " + stats.Count + " stats");
}
}
async void OnUpgrade()
{
await Selector.selectedBuilding.Upgrade();
OnUpgradeMenuClicked();
}
void OnInfoClicked()
{
Debug.Log("Opening Info Menu for : " + Selector.selectedBuilding.buildingData.name);

View File

@@ -49,6 +49,7 @@ public class WorldItemSelector : MonoBehaviour
public static class Selector{
public static Building selectedBuilding;
public static BuildingData selectedData => selectedBuilding.buildingData;
public static UnityEvent OnSelectedChanged = new UnityEvent();
public static void selectBuilding(Building e){