Files
5.24BuYu/Assets/MyGame/aa/UI/Home/Sub/UIHome_BY_BackPackPanel.cs
T
2026-06-25 01:48:07 +08:00

91 lines
3.0 KiB
C#

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 UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.UI;
public class UIHome_BY_BackPackPanel : SubUIBase
{
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 BackPackPropItem prefabItem;
[Header("道具详情")]
public TextMeshProUGUI tMP_Name;
public TextMeshProUGUI tMP_Description;
public Image img_Prop;
public string propID; //这里是道具的ID 之后用来触发使用事件
public ScrollRect scrollRect;
public Button btn_Use;
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);
}
bool isfirst = true;
foreach (BaseProductCount product in propsID_Dic.Values)
{
if (isfirst)
{
tMP_Name.text = product.name;
tMP_Description.text = product.desc;
propID = product.number;
WebTool.DownImage(APIManager.baseURL + product.imageUrl, (texture) =>
{
img_Prop.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f);
});
isfirst = false;
}
GameObject obj = Instantiate(prefabItem.gameObject, pageParent);
var tempItem = obj.GetComponent<BackPackPropItem>();
tempItem.Init(APIManager.baseURL + product.imageUrl, product.count, (PropEnum)product.type);
propsObjHashCode_Dic[obj.GetHashCode()] = product; //不记得干什么用了
obj.GetComponent<Toggle>().onValueChanged.AddListener((value) =>
{
if (value)
{
tMP_Name.text=product.name;
tMP_Description.text = product.desc;
propID = product.number;
WebTool.DownImage(APIManager.baseURL + product.imageUrl, (texture) =>
{
img_Prop.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f);
});
}
});
}
}
}