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(){ public void Upgrade(){
if(curLevel >= buildingData.levels.Count-1){Debug.Log("Already max");return;} if(curLevel >= buildingData.levels.Count-1){Debug.Log("Already max");return;}
int cost = buildingData.levels[curLevel+1].price; 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) switch (curLevel)
{ {

View File

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

View File

@@ -18,8 +18,22 @@ public class BuildingManager : MonoBehaviour
} }
public void UpdateBuildings(){ public async void UpdateBuildings(){
Debug.Log("Im getting called"); 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){ foreach (Building building in buildings){
bool buildingExists = false; bool buildingExists = false;
foreach (BuildingState buildingState in DBmanager.buildingStates){ foreach (BuildingState buildingState in DBmanager.buildingStates){

View File

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

View File

@@ -5,49 +5,68 @@ using UnityEngine.UI;
public class SkinShopItem : MonoBehaviour public class SkinShopItem : MonoBehaviour
{ {
public Image spaceshipImg; public Image spaceshipImg;
public Image backgroundImg; [Tooltip("In order of: normal, rare, legendary. 3 items required")]
public Button buyBtn; public GameObject[] banners;
public Button equipBtn; public Image frame;
public GameObject equippedIndicator; public GameObject notPurchasedIndicator;
public new string name; public SkinShopItemData skinData;
public int price;
public TMPro.TMP_Text nameTxt;
void Start(){
buyBtn.onClick.AddListener(onBuy);
equipBtn.onClick.AddListener(onEquip);
}
public void Set(SkinShopItemData data){ public void Set(SkinShopItemData data){
name = data.name; skinData = data;
nameTxt.text = data.name;
price = data.price;
// newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor); // newItem.backgroundImg.color = (skinsData.skins[i].skinType==SkinType.Base) ? basicColor : (skinsData.skins[i].skinType==SkinType.Rare ? rareColor : legendaryColor);
spaceshipImg.sprite = data.image; 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)); UpdateFrame();
equipBtn.gameObject.SetActive(!buyBtn.gameObject.activeSelf);
if(SkinShopManager.GetEquipedSkin() == name){ banners[0].SetActive(data.skinType== SkinType.Base);
equipBtn.gameObject.SetActive(false); banners[1].SetActive(data.skinType== SkinType.Rare);
equippedIndicator.SetActive(true); banners[2].SetActive(data.skinType== SkinType.Legendary);
}
public void UpdateFrame(){
if(SkinShopManager.GetEquipedSkin() == skinData.name){
frame.enabled=true;
frame.color = Color.cyan;
}else{ }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(){ public void OnClick(){
SkinShopManager.EquipSkin(name); SkinShopManager.instance.SelectItem(skinData);
SkinShopManager.instance.Populate(); }
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;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
public class SkinShopManager : MonoBehaviour public class SkinShopManager : MonoBehaviour
{ {
public static SkinShopManager instance; public static SkinShopManager instance;
public SkinsData skinsData; public SkinsData skinsData;
public TMPro.TMP_Text metalsTxt;
public GameObject listItemPrefab; public GameObject listItemPrefab;
public Transform listItemsParent; public Transform listItemsParent;
public Button btn_Equip;
public Color basicColor = Color.grey; public Button btn_Buy;
public Color rareColor = Color.blue; public static SkinShopItemData selectedSkin;
public Color legendaryColor = Color.red; List<SkinShopItem> skinShopItems=new List<SkinShopItem>();
void Awake() { void Awake() {
instance = this; instance = this;
@@ -22,27 +23,72 @@ public class SkinShopManager : MonoBehaviour
void Start() void Start()
{ {
Populate(); Populate();
}
// Update is called once per frame btn_Equip.onClick.AddListener(onEquip);
void Update() btn_Buy.onClick.AddListener(onBuy);
{
} }
public void Populate(){ 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 //PURGE
for(int i=0;i < listItemsParent.childCount;i++){ for(int i=0;i < listItemsParent.childCount;i++){
Destroy(listItemsParent.GetChild(i).gameObject); Destroy(listItemsParent.GetChild(i).gameObject);
} }
skinShopItems = new List<SkinShopItem>();
for(int i=0; i<skinsData.skins.Length;i++){ for(int i=0; i<skinsData.skins.Length;i++){
SkinShopItem newItem = Instantiate(listItemPrefab, listItemsParent).GetComponent<SkinShopItem>(); SkinShopItem newItem = Instantiate(listItemPrefab, listItemsParent).GetComponent<SkinShopItem>();
newItem.Set(skinsData.skins[i]); 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){ public static void EquipSkin(string skin){

View File

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

View File

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

View File

@@ -1,40 +1,20 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000 --- !u!114 &11400000
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0} m_GameObject: {fileID: 0}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3} m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Hall m_Name: Hall
m_EditorClassIdentifier: m_EditorClassIdentifier:
buildingName: Hall buildingName: Hall
levels: levels: []
- level: 1 description: This is the Hall (Main Hall)
stats: collectable: 0
- name: Stat 1 resourceType: 0
value: 120 productinoRates: []
- 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: []

View File

@@ -1,26 +1,44 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000 --- !u!114 &11400000
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0} m_GameObject: {fileID: 0}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3} m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: Mine m_Name: Mine
m_EditorClassIdentifier: m_EditorClassIdentifier:
buildingName: Rocket Repair buildingName: Gold Mine
levels: levels:
- level: 1 - level: 1
stats: stats:
- name: Production rate - name: Gold Per H
value: 10% value: 100
price: 8500 image: {fileID: 21300000, guid: ffe128a5f047f43d9a494e099634504e, type: 3}
xpGain: 2000 price: 8500
description: This is a Rocket Repair xpGain: 2000
collectable: 0 - level: 1
resourceType: 0 stats:
productinoRates: [] - 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 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000 --- !u!114 &11400000
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0} m_GameObject: {fileID: 0}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3} m_Script: {fileID: 11500000, guid: 0f0adcd9d9fe1cd78b1cc91fd454aa46, type: 3}
m_Name: O2Mine m_Name: O2Mine
m_EditorClassIdentifier: m_EditorClassIdentifier:
buildingName: Oxygen Mine buildingName: Rocket Hanger
levels: levels:
- level: 1 - level: 1
stats: stats:
- name: Oxygen - name: Oxygen
value: 10 value: 10
- name: Power image: {fileID: 0}
value: 2 - name: Power
price: 20000 value: 2
xpGain: 2000 image: {fileID: 0}
description: This is an Oxygen Mine price: 20000
collectable: 1 xpGain: 2000
resourceType: 1 description: Buy and craft new skins with this structure.
productinoRates: collectable: 0
- 0.1 resourceType: 1
productinoRates:
- 0.1