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

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
{
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 UnityEngine;
using UnityEngine.UI;
@ -12,19 +9,23 @@ public class ShopTypeitemPrefab : MonoBehaviour
ShopItemData shopItemData;
public void Set(ShopItemData shopItemData)
public bool Set(ShopItemData shopItemData)
{
bool is_active;
this.shopItemData = shopItemData;
pay.text = "£Ü" + shopItemData.buy.ToString();
OnSet(shopItemData);
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 TypeBuy() { }
public void BuyItemButton()
{
bool is_active;
BuyShopItemResp resp = new BuyShopItemResp();
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);
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);
}
}

View File

@ -46,10 +46,23 @@ public class ShopUiType1 : MonoBehaviour
if (item.Value.shop_index == shop_index)
{
GameObject obj = Instantiate(itemPrefab, itemContent);
obj.GetComponent<ShopType1itemPrefab>().Set(item.Value);
ShopType1itemPrefab prefab = obj.GetComponent<ShopType1itemPrefab>();
if (prefab.Set(item.Value))
{
prefab.Set2(this);
maxPage++;
}
}
}
defaultPos = ((maxPage - 1) * 1290) / 2;
page.anchoredPosition = new Vector2(defaultPos, 0);
animValue = 1;
}
public void newSet()
{
maxPage--;
defaultPos = ((maxPage - 1) * 1290) / 2;
page.anchoredPosition = new Vector2(defaultPos, 0);
animValue = 1;