SkinShop done and building menus integrated

This commit is contained in:
Sewmina 2022-09-01 03:40:19 +05:30
parent d30fe75b7d
commit 37d9c49e69
20 changed files with 14925 additions and 6084 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0cf4a9b3fa28e873d883f846ed616805
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e14cc4e73f5c837c4aac9f21a879de8b
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f4504a93d75dd06098a35a997fdec247
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -53,7 +53,7 @@ public class Building : MonoBehaviour
public void 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");
Debug.Log("Upgrading " + buildingData.buildingName + " for " + cost + " coins");
switch (curLevel)
{

View File

@ -28,12 +28,13 @@ public static class CollectablesData{
public class BuildingStat{
public string name;
public string value;
public Sprite image;
public BuildingStat(string _name, string _value){
public BuildingStat(string _name, string _value, Sprite _image){
name= _name;
value = _value;
image= _image;
}
}

View File

@ -18,8 +18,22 @@ public class BuildingManager : MonoBehaviour
}
public void UpdateBuildings(){
Debug.Log("Im getting called");
public async void UpdateBuildings(){
foreach (Building building in buildings){
if(!building.gameObject.activeSelf){
continue;
}
bool buildingExists = false;
foreach (BuildingState buildingState in DBmanager.buildingStates){
if(buildingState.id == building.buildingData.buildingName){
buildingExists =true;
}
}
if(!buildingExists){
await DBmanager.AddBuilding(building.buildingData);
}
}
foreach (Building building in buildings){
bool buildingExists = false;
foreach (BuildingState buildingState in DBmanager.buildingStates){

View File

@ -21,7 +21,7 @@ public class CollectBtn : MonoBehaviour
void Update()
{
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * productionRate);
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f));
txt.text = ((int)collectableAmount).ToString();
btn.interactable = collectableAmount > 1;
@ -35,7 +35,7 @@ public class CollectBtn : MonoBehaviour
}
async void OnClick(){
collectableAmount=((DateTime.Now - lastCollected).TotalSeconds * productionRate);
collectableAmount=((DateTime.UtcNow - lastCollected).TotalSeconds * ((productionRate/60f)/60f));
lastCollected = await DBmanager.GetNetworkTime();
switch (resourceType){
case CollectablesData.ResourceType.Metal:

View File

@ -5,49 +5,68 @@ using UnityEngine.UI;
public class SkinShopItem : MonoBehaviour
{
public Image spaceshipImg;
public Image backgroundImg;
public Button buyBtn;
public Button equipBtn;
public GameObject equippedIndicator;
public new string name;
public int price;
public TMPro.TMP_Text nameTxt;
void Start(){
buyBtn.onClick.AddListener(onBuy);
equipBtn.onClick.AddListener(onEquip);
}
[Tooltip("In order of: normal, rare, legendary. 3 items required")]
public GameObject[] banners;
public Image frame;
public GameObject notPurchasedIndicator;
public SkinShopItemData skinData;
public void Set(SkinShopItemData data){
name = data.name;
nameTxt.text = data.name;
price = data.price;
skinData = data;
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
spaceshipImg.sprite = data.image;
buyBtn.GetComponentInChildren<TMPro.TMP_Text>().text = price.ToString();
buyBtn.interactable = DBmanager.Metal >= price;
buyBtn.gameObject.SetActive(!(DBmanager.SkinsPurchased.Contains(name) || price<=0));
equipBtn.gameObject.SetActive(!buyBtn.gameObject.activeSelf);
UpdateFrame();
if(SkinShopManager.GetEquipedSkin() == name){
equipBtn.gameObject.SetActive(false);
equippedIndicator.SetActive(true);
banners[0].SetActive(data.skinType== SkinType.Base);
banners[1].SetActive(data.skinType== SkinType.Rare);
banners[2].SetActive(data.skinType== SkinType.Legendary);
}
public void UpdateFrame(){
if(SkinShopManager.GetEquipedSkin() == skinData.name){
frame.enabled=true;
frame.color = Color.cyan;
}else{
equippedIndicator.SetActive(false);
frame.enabled=false;
}
if(!DBmanager.SkinsPurchased.Contains(skinData.name)){
frame.color = Color.red;
notPurchasedIndicator.SetActive(true);
}else{
notPurchasedIndicator.SetActive(false);
}
}
void onEquip(){
SkinShopManager.EquipSkin(name);
SkinShopManager.instance.Populate();
public void OnClick(){
SkinShopManager.instance.SelectItem(skinData);
}
public void OnSelectionChanged(string selectedItem){
if(selectedItem == skinData.name){
frame.enabled=true;
}else{
frame.enabled = false;
}
if(SkinShopManager.GetEquipedSkin() == skinData.name){
frame.enabled = true;
}
}
void onBuy(){
SkinShopItemData data = new SkinShopItemData(){name=name, price=price};
DBmanager.PurchaseSkin(data);
SkinShopManager.instance.Populate();
}
// void onEquip(){
// SkinShopManager.EquipSkin(name);
// SkinShopManager.instance.Populate();
// }
// void onBuy(){
// SkinShopItemData data = new SkinShopItemData(){name=name, price=price};
// DBmanager.PurchaseSkin(data);
// SkinShopManager.instance.Populate();
// }
}

View File

@ -1,20 +1,21 @@
using TMPro;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SkinShopManager : MonoBehaviour
{
public static SkinShopManager instance;
public SkinsData skinsData;
public TMPro.TMP_Text metalsTxt;
public GameObject listItemPrefab;
public Transform listItemsParent;
public Color basicColor = Color.grey;
public Color rareColor = Color.blue;
public Color legendaryColor = Color.red;
public Button btn_Equip;
public Button btn_Buy;
public static SkinShopItemData selectedSkin;
List<SkinShopItem> skinShopItems=new List<SkinShopItem>();
void Awake() {
instance = this;
@ -22,27 +23,72 @@ public class SkinShopManager : MonoBehaviour
void Start()
{
Populate();
}
// Update is called once per frame
void Update()
{
btn_Equip.onClick.AddListener(onEquip);
btn_Buy.onClick.AddListener(onBuy);
}
public void Populate(){
//Validate skins list
if(DBmanager.SkinsPurchased.Count <=0){
foreach(SkinShopItemData skin in skinsData.skins){
if(skin.price==0){ //Defaults
DBmanager.PurchaseSkin(skin);
if(GetEquipedSkin().Length <=0){
EquipSkin(skin.name);
}
}
}
}
//PURGE
for(int i=0;i < listItemsParent.childCount;i++){
Destroy(listItemsParent.GetChild(i).gameObject);
}
skinShopItems = new List<SkinShopItem>();
for(int i=0; i<skinsData.skins.Length;i++){
SkinShopItem newItem = Instantiate(listItemPrefab, listItemsParent).GetComponent<SkinShopItem>();
newItem.Set(skinsData.skins[i]);
newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
skinShopItems.Add(newItem);
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
}
metalsTxt.text = DBmanager.Metal.ToString();
SelectItem(selectedSkin);
}
public void SelectItem(SkinShopItemData data){
selectedSkin = data;
if(data==null){
btn_Equip.gameObject.SetActive(false); btn_Buy.gameObject.SetActive(false);
return;
}
if(DBmanager.SkinsPurchased.Contains(data.name)){ // <-- purchased
btn_Equip.gameObject.SetActive(true);
btn_Buy.gameObject.SetActive(false);
btn_Equip.interactable = GetEquipedSkin() != data.name; // <-- disable equip button if already equipped
}else{
btn_Buy.gameObject.SetActive(true);
btn_Equip.gameObject.SetActive(false);
btn_Buy.interactable = DBmanager.Metal >= data.price;
btn_Buy.GetComponentInChildren<TMP_Text>().text = data.price.ToString();
}
foreach(SkinShopItem item in skinShopItems){
item.OnSelectionChanged(data.name);
}
}
void onEquip(){
EquipSkin(selectedSkin.name);
Populate();
}
void onBuy(){
DBmanager.PurchaseSkin(selectedSkin);
SkinShopManager.instance.Populate();
}
public static void EquipSkin(string skin){

View File

@ -9,16 +9,20 @@ public class SelectedItemMenu : MonoBehaviour
public Button upgradeMenuBtn;
public Button infoBtn;
public CollectBtn collectBtn;
public Button joinHallBtn;
public Button repairRocketsBtn;
// public Button joinHallBtn;
// public Button repairRocketsBtn;
[Header("info menu")]
public GameObject infoMenu;
public GameObject[] tierIndicators;
public TMP_Text buildingName;
public TMP_Text descriptionTxt;
[Header("upgrade menu")]
public GameObject upgradeMenu;
public Transform upgrade_statParent;
public GameObject[] upgrade_tierIndicators;
public TMP_Text upgrade_buildingName;
public Button upgradeBtn;
[Header("Special buildings")]
@ -57,16 +61,16 @@ public class SelectedItemMenu : MonoBehaviour
collectBtn.gameObject.SetActive(false);
}
joinHallBtn.gameObject.SetActive((Selector.selectedData == mainHall));
repairRocketsBtn.gameObject.SetActive((Selector.selectedData == rocketRepair));
// joinHallBtn.gameObject.SetActive((Selector.selectedData == mainHall));
// repairRocketsBtn.gameObject.SetActive((Selector.selectedData == rocketRepair));
}
else
{
upgradeMenuBtn.gameObject.SetActive(false);
infoBtn.gameObject.SetActive(false);
collectBtn.gameObject.SetActive(false);
joinHallBtn.gameObject.SetActive(false);
repairRocketsBtn.gameObject.SetActive(false);
// joinHallBtn.gameObject.SetActive(false);
// repairRocketsBtn.gameObject.SetActive(false);
}
upgradeMenu.SetActive(false);
@ -78,7 +82,10 @@ public class SelectedItemMenu : MonoBehaviour
// Debug.Log("Opening Upgrade Menu for : " + Selector.selectedBuilding.buildingData.name);
upgradeMenu.SetActive(true);
upgrade_buildingName.text = Selector.selectedBuilding.buildingData.buildingName;
for(int i=0; i < upgrade_tierIndicators.Length;i++){
upgrade_tierIndicators[i].SetActive( Selector.selectedBuilding.curLevel == i);
}
if (Selector.selectedBuilding.curLevel < Selector.selectedData.levels.Count - 1)
{
upgradeBtn.interactable = (Selector.selectedData.levels[Selector.selectedBuilding.curLevel + 1].price < DBmanager.Coins);
@ -102,10 +109,11 @@ 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;
upgrade_statParent.GetChild(i).GetChild(2).GetComponent<Image>().sprite = stats[i].image;
}
}
if (upgrade_statParent.childCount > stats.Count)
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");
}
@ -123,6 +131,10 @@ public class SelectedItemMenu : MonoBehaviour
Debug.Log("Opening Info Menu for : " + Selector.selectedBuilding.buildingData.name);
infoMenu.SetActive(true);
buildingName.text = Selector.selectedBuilding.buildingData.buildingName;
for(int i=0; i < tierIndicators.Length;i++){
tierIndicators[i].SetActive( Selector.selectedBuilding.curLevel == i);
}
descriptionTxt.text = Selector.selectedBuilding.buildingData.description;
}

View File

@ -1,24 +1,20 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Generic Building
m_EditorClassIdentifier:
buildingName: Generic Building
levels:
- level: 1
stats: []
price: 1000
xpGain: 2000
description: This is just a Generic Building
collectable: 0
resourceType: 0
productinoRates: []
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Generic Building
m_EditorClassIdentifier:
buildingName: Generic Building
levels: []
description: This is just a Generic Building
collectable: 0
resourceType: 0
productinoRates: []

View File

@ -1,40 +1,20 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Hall
m_EditorClassIdentifier:
buildingName: Hall
levels:
- level: 1
stats:
- name: Stat 1
value: 120
- name: Power
value: 2
- name: Energy
value: 50
price: 10000
xpGain: 120
- level: 2
stats:
- name: Stat 1
value: 200
- name: Power
value: 30
- name: Energy
value: 500
price: 15000
xpGain: 5000
description: This is the Hall (Main Hall)
collectable: 0
resourceType: 0
productinoRates: []
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Hall
m_EditorClassIdentifier:
buildingName: Hall
levels: []
description: This is the Hall (Main Hall)
collectable: 0
resourceType: 0
productinoRates: []

View File

@ -1,26 +1,44 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Mine
m_EditorClassIdentifier:
buildingName: Rocket Repair
levels:
- level: 1
stats:
- name: Production rate
value: 10%
price: 8500
xpGain: 2000
description: This is a Rocket Repair
collectable: 0
resourceType: 0
productinoRates: []
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Mine
m_EditorClassIdentifier:
buildingName: Gold Mine
levels:
- level: 1
stats:
- name: Gold Per H
value: 100
image: {fileID: 21300000, guid: ffe128a5f047f43d9a494e099634504e, type: 3}
price: 8500
xpGain: 2000
- level: 1
stats:
- name: Gold Per H
value: +50
image: {fileID: 21300000, guid: ffe128a5f047f43d9a494e099634504e, type: 3}
price: 8500
xpGain: 2000
- level: 1
stats:
- name: Gold Per H
value: +150
image: {fileID: 21300000, guid: ffe128a5f047f43d9a494e099634504e, type: 3}
price: 8500
xpGain: 5000
description: This structure is digging for gold 24/7.
collectable: 1
resourceType: 0
productinoRates:
- 100
- 150
- 300

View File

@ -1,29 +1,31 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: O2Mine
m_EditorClassIdentifier:
buildingName: Oxygen Mine
levels:
- level: 1
stats:
- name: Oxygen
value: 10
- name: Power
value: 2
price: 20000
xpGain: 2000
description: This is an Oxygen Mine
collectable: 1
resourceType: 1
productinoRates:
- 0.1
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: O2Mine
m_EditorClassIdentifier:
buildingName: Rocket Hanger
levels:
- level: 1
stats:
- name: Oxygen
value: 10
image: {fileID: 0}
- name: Power
value: 2
image: {fileID: 0}
price: 20000
xpGain: 2000
description: Buy and craft new skins with this structure.
collectable: 0
resourceType: 1
productinoRates:
- 0.1