商店修改

This commit is contained in:
wulongxiao 2024-11-27 23:39:41 +08:00
parent f10cdf47f8
commit 7360d00793
4 changed files with 21 additions and 22 deletions

View File

@ -17,7 +17,7 @@ public class Scene_main_jiekou :Base
private MallResponsePro _mallResponsePro;//商城列表结构体
private getMallList21 _getMallList21;//商城列表获取方法
//商城info字典
public Dictionary<int, ProductPro> shopItemDic;
public Dictionary<int, ProductPro> shopItemDic = new Dictionary<int, ProductPro>();
// Start is called before the first frame update
@ -52,21 +52,26 @@ public class Scene_main_jiekou :Base
public async Task ShopInfo()
{
//瓊품헌왕
shopItemDic = null;
// 每次调用时清空字典,确保是最新数据
shopItemDic.Clear();
// 清空商城数据
_mallResponsePro = null;
_getMallList21 = null;
//路畇畇흙
// 重新实例化商城相关对象
_mallResponsePro = new MallResponsePro();
_getMallList21 = new getMallList21();
// 异步获取商城数据
_mallResponsePro = await _getMallList21.getMallList(1, 1, 20);
// 将商品信息存入字典
foreach (ProductPro go in _mallResponsePro.Data.DataList)
{
shopItemDic.Add(go.ProductId,go);
}
// 更新字典中的商品信息
shopItemDic[go.ProductId] = go;
}
}

View File

@ -28,9 +28,9 @@ public class main_shop :BaseUIPanel
return;
}
//await Scene_main_jiekou.instance.ShopInfo();
await Scene_main_jiekou.instance.ShopInfo();
//获取商城列表
Debug.Log("»ñÈ¡É̳ÇÁбí");
Debug.Log("获取商城列表才能实例化panel,但是更新显示让panel来");
// 实例化 Panel
GameObject.Instantiate(Panel, canvas.transform);

View File

@ -37,19 +37,19 @@ public class itemInfo : MonoBehaviour
this.id = id;
}
public void initShow(int id, Sprite icon, string name, float price)
public void initShow(int id, Sprite icon, string name, string price)
{
this.id = id;
iconImage.sprite = icon;
nameText.text = name;
priceText.text = price.ToString();
priceText.text = price;
}
public void initShow(int id, string name, float price)
public void initShow(int id, string name, string price)
{
this.id = id;
nameText.text = name;
priceText.text = price.ToString();
priceText.text = price;
}
}

View File

@ -10,16 +10,10 @@ public class shopPanel: ui_huodong
void initShop()
{
int index= Scene_main_jiekou.instance._mallResponsePro.Data.TotalCount;//商城的商品数量
foreach (itemInfo item in itemInfos)
int index = 0;
foreach (KeyValuePair<int, ProductPro> go in Scene_main_jiekou.instance.shopItemDic)
{
if (index>0)
{
item.gameObject.SetActive(true);
}
itemInfos[index].initShow(go.Value.ProductId,go.Value.ProductName,go.Value.ProductPic.ToString());
}
}