Files
5.24BuYu/Assets/MyGame/aa/UI/Home/Sub/UIHome_BY_BackPackPanel.cs
T

78 lines
2.3 KiB
C#
Raw Normal View History

2026-03-27 15:18:35 +08:00
using Assets.Framework.Tool;
2026-04-13 18:30:55 +08:00
using Assets.MyGame.Scripts.Net;
2026-03-27 15:18:35 +08:00
using Assets.MyGame.Scripts.Net.API.UserData_SubClass;
using System.Collections;
2025-12-13 18:18:28 +08:00
using System.Collections.Generic;
2026-03-27 15:18:35 +08:00
using TMPro;
2026-04-17 18:30:51 +08:00
using Unity.VisualScripting;
2025-12-13 18:18:28 +08:00
using UnityEngine;
2026-03-27 15:18:35 +08:00
using UnityEngine.UI;
2025-12-13 18:18:28 +08:00
2025-12-26 11:15:56 +08:00
public class UIHome_BY_BackPackPanel : SubUIBase
2025-12-13 18:18:28 +08:00
{
2026-03-27 15:18:35 +08:00
public List<BaseProductCount> props;
public Dictionary<string,BaseProductCount> propsID_Dic = new Dictionary<string,BaseProductCount>();
public Dictionary<int,BaseProductCount> propsObjHashCode_Dic = new Dictionary<int, BaseProductCount>();
public Transform pageParent;
public GameObject prefabItem;
public TextMeshProUGUI tMP_Name;
public TextMeshProUGUI tMP_Description;
public TextMeshProUGUI text_PageNum;
public int pageCountNum = 0;
public int pageNum = 1;
public ScrollRect scrollRect;
public override void Awake()
2025-12-13 18:18:28 +08:00
{
2026-03-27 15:18:35 +08:00
base.Awake();
2025-12-13 18:18:28 +08:00
}
2026-03-27 15:18:35 +08:00
protected override void OnShow(object args = null)
2025-12-13 18:18:28 +08:00
{
2026-03-27 15:18:35 +08:00
base.OnShow(args);
props = GameManager.Instance.user.props;
foreach (BaseProductCount product in props)
{
propsID_Dic[product.number]=product;
if (product.count<=0)
{
2026-04-17 18:30:51 +08:00
2026-03-27 15:18:35 +08:00
propsID_Dic.Remove(product.number);
}
}
2026-04-17 18:30:51 +08:00
for (int j = pageParent.childCount-1; j >=0 ; j--)
{
Destroy(pageParent.GetChild(j).gameObject);
}
2026-03-27 15:18:35 +08:00
int i=0;
2025-12-13 18:18:28 +08:00
2026-04-17 18:30:51 +08:00
2026-03-27 15:18:35 +08:00
pageCountNum++;
foreach (BaseProductCount product in propsID_Dic.Values)
{
2026-04-17 18:30:51 +08:00
GameObject obj = Instantiate(prefabItem,pageParent);
2026-03-27 15:18:35 +08:00
propsObjHashCode_Dic[obj.GetHashCode()] = product;
obj.transform.GetChild(1).GetComponent<TextMeshProUGUI>().text= product.count.ToString();
obj.GetComponent<Toggle>().onValueChanged.AddListener((value) =>
{
if (value)
{
tMP_Name.text=product.name;
tMP_Description.text = product.desc;
}
});
2026-04-13 18:30:55 +08:00
WebTool.DownImage(APIManager.baseURL+product.imageUrl, (texture) =>
2026-03-27 15:18:35 +08:00
{
obj.transform.GetChild(0).GetComponent<Image>().sprite = Sprite.Create(texture,new Rect(0f,0f,90,90),Vector2.one*0.5f) ;
});
i++;
}
2026-04-17 18:30:51 +08:00
2026-03-27 15:18:35 +08:00
2025-12-13 18:18:28 +08:00
}
}