using Assets.Framework.Tool; using Assets.MyGame.Scripts.Net; using Assets.MyGame.Scripts.Net.API.UserData_SubClass; using System.Collections; using System.Collections.Generic; using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; public class UIHome_BY_BackPackPanel : SubUIBase { public List props; public Dictionary propsID_Dic = new Dictionary(); public Dictionary propsObjHashCode_Dic = new Dictionary(); 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() { base.Awake(); } protected override void OnShow(object args = null) { base.OnShow(args); props = GameManager.Instance.user.props; foreach (BaseProductCount product in props) { propsID_Dic[product.number]=product; if (product.count<=0) { propsID_Dic.Remove(product.number); } } for (int j = pageParent.childCount-1; j >=0 ; j--) { Destroy(pageParent.GetChild(j).gameObject); } int i=0; pageCountNum++; foreach (BaseProductCount product in propsID_Dic.Values) { GameObject obj = Instantiate(prefabItem,pageParent); propsObjHashCode_Dic[obj.GetHashCode()] = product; obj.transform.GetChild(1).GetComponent().text= product.count.ToString(); obj.GetComponent().onValueChanged.AddListener((value) => { if (value) { tMP_Name.text=product.name; tMP_Description.text = product.desc; } }); WebTool.DownImage(APIManager.baseURL+product.imageUrl, (texture) => { obj.transform.GetChild(0).GetComponent().sprite = Sprite.Create(texture,new Rect(0f,0f,90,90),Vector2.one*0.5f) ; }); i++; } } }