상점 구매시 아이템 삭제 추가

This commit is contained in:
김판돌 2024-03-23 19:28:20 +09:00
parent d5f71abd2e
commit 112c30d005
3 changed files with 39 additions and 11 deletions

View File

@ -1,5 +1,14 @@
public class ShopType1itemPrefab : ShopTypeitemPrefab public class ShopType1itemPrefab : ShopTypeitemPrefab
{ {
ShopUiType1 shopUiType1;
public void Set2(ShopUiType1 shopUiType1)
{
this.shopUiType1=shopUiType1;
}
protected override void TypeBuy()
{
shopUiType1.newSet();
}
} }

View File

@ -1,6 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro; using TMPro;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -12,19 +9,23 @@ public class ShopTypeitemPrefab : MonoBehaviour
ShopItemData shopItemData; ShopItemData shopItemData;
public void Set(ShopItemData shopItemData) public bool Set(ShopItemData shopItemData)
{ {
bool is_active;
this.shopItemData = shopItemData; this.shopItemData = shopItemData;
pay.text = "£Ü" + shopItemData.buy.ToString(); pay.text = "£Ü" + shopItemData.buy.ToString();
OnSet(shopItemData); OnSet(shopItemData);
Debug.Log($"{shopItemData.name} : {shopItemData.buy_count} : {shopItemData.buy_count != 0}"); Debug.Log($"{shopItemData.name} : {shopItemData.buy_count} : {shopItemData.buy_count != 0}");
gameObject.SetActive(shopItemData.buy_count != 0); is_active = (shopItemData.buy_count != 0);
gameObject.SetActive(is_active);
return is_active;
} }
virtual protected void OnSet(ShopItemData shopItemData) {} virtual protected void OnSet(ShopItemData shopItemData) {}
virtual protected void TypeBuy() { }
public void BuyItemButton() public void BuyItemButton()
{ {
bool is_active;
BuyShopItemResp resp = new BuyShopItemResp(); BuyShopItemResp resp = new BuyShopItemResp();
resp.Request((data) => resp.Request((data) =>
{ {
@ -42,7 +43,12 @@ public class ShopTypeitemPrefab : MonoBehaviour
GetItemWindows.Instance.SetUI(addGold, addCash, data.deck_unit, data.equipment, data.consumableItem, data.etcItem); GetItemWindows.Instance.SetUI(addGold, addCash, data.deck_unit, data.equipment, data.consumableItem, data.etcItem);
shopItemData.buy_count--; shopItemData.buy_count--;
gameObject.SetActive(shopItemData.buy_count != 0); is_active = (shopItemData.buy_count != 0);
if (!is_active)
{
gameObject.SetActive(is_active);
TypeBuy();
}
}, shopItemData.index, shopItemData.id); }, shopItemData.index, shopItemData.id);
} }
} }

View File

@ -41,13 +41,18 @@ public class ShopUiType1 : MonoBehaviour
public void Set(long shop_index) public void Set(long shop_index)
{ {
foreach(var item in Statics.shopItems) foreach (var item in Statics.shopItems)
{ {
if(item.Value.shop_index == shop_index) if (item.Value.shop_index == shop_index)
{ {
GameObject obj = Instantiate(itemPrefab, itemContent); GameObject obj = Instantiate(itemPrefab, itemContent);
obj.GetComponent<ShopType1itemPrefab>().Set(item.Value); ShopType1itemPrefab prefab = obj.GetComponent<ShopType1itemPrefab>();
maxPage++; if (prefab.Set(item.Value))
{
prefab.Set2(this);
maxPage++;
}
} }
} }
defaultPos = ((maxPage - 1) * 1290) / 2; defaultPos = ((maxPage - 1) * 1290) / 2;
@ -55,6 +60,14 @@ public class ShopUiType1 : MonoBehaviour
animValue = 1; animValue = 1;
} }
public void newSet()
{
maxPage--;
defaultPos = ((maxPage - 1) * 1290) / 2;
page.anchoredPosition = new Vector2(defaultPos, 0);
animValue = 1;
}
public void LeftButton() public void LeftButton()
{ {
if (index == 0) if (index == 0)