_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Scene_main/Scene_main_jiekou.cs
2024-12-13 15:27:51 +08:00

124 lines
3.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
public class Scene_main_jiekou :Base
{
public static Scene_main_jiekou instance;
public mainBTN _mainBTN;
//用户信息
private RealPlayerInfo _realPlayerInfo;//用户信息结构体
private queryPlayerInfo _queryPlayerInfo;//用户信息
//商城信息
private MallResponsePro _mallResponsePro;//商城列表结构体
private getMallList21 _getMallList21;//商城列表获取方法
//商城info字典
public Dictionary<int, ProductPro> shopItemDic = new Dictionary<int, ProductPro>();
public getProductResponse _getProductResponse;
//玩家的详细地址,电话。。。。。
private AdressList83 _adressList83;
private AdressResponse _adressResponse;
//买东西
private BuyProduct23 _buyProduct23;
[HideInInspector]
public bool IsBuyGet = false;
// Start is called before the first frame update
private void Awake()
{
instance = this;
Global.global.scene_Main_Jiekou = this;
//testLogo();
getPlayerInfo();
// getShopInfo();
}
public async void getPlayerInfo()
{
await PlayerInfoAsync();
/*Debug.Log(_realPlayerInfo.data.nickName);
Debug.Log(_realPlayerInfo.data.voluteCoin);
Debug.Log(_realPlayerInfo.data.beansCoin);*/
_mainBTN.UpDatePlayer(_realPlayerInfo.data.headImg, _realPlayerInfo.data.nickName, _realPlayerInfo.data.voluteCoin.ToString("f1") , _realPlayerInfo.data.beansCoin.ToString("f1"));
}
async Task PlayerInfoAsync()
{
_realPlayerInfo = new RealPlayerInfo();
_queryPlayerInfo = new queryPlayerInfo();
_realPlayerInfo = await _queryPlayerInfo.QueryPlayerInfoPro();
}
public async Task ShopInfo()
{
// 每次调用时清空字典,确保是最新数据
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[go.ProductId] = go;
}
}
public async Task ShopItemDetail(int id)
{
_getProductResponse = null;
productInfo22 _productInfo22 = new productInfo22();
_getProductResponse = await _productInfo22.productInfo(id);
}
public async Task ShopOneItem(int id)
{
_adressResponse = new AdressResponse();
_adressList83 = new AdressList83();
_adressResponse = await _adressList83.AdressList();
_buyProduct23 = new BuyProduct23();
BuyProductResponse buyRes = await _buyProduct23.BuyProduct(id, _adressResponse.data[0].userId, _adressResponse.data[0].receiveName, _adressResponse.data[0].receivePhone, _adressResponse.data[0].area, _adressResponse.data[0].address);
if (buyRes.code == 200)
{
IsBuyGet = true;
}
else
{
IsBuyGet = false;
}
}
}