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

158 lines
5.7 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;
using static UnityEditor.MaterialProperty;
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;
public TextMeshProUGUI tMP_Gold;
public TextMeshProUGUI tMP_Diamond;
[Header("道具详情")]
public TextMeshProUGUI tMP_Name;
public TextMeshProUGUI tMP_Description;
public Image img_Prop;
public string propID; //这里是道具的ID 之后用来触发使用事件
public PropEnum propType; //这里是道具的类型 之后用来触发使用事件
public ScrollRect scrollRect;
public Button btn_Use;
public override void Awake()
{
base.Awake();
}
protected override void OnShow(object args = null)
{
base.OnShow(args);
tMP_Gold.text= GameManager.Instance.user.assets.gold.ToString();
tMP_Diamond.text= GameManager.Instance.user.assets.diamond.ToString();
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;
btn_Use.onClick.RemoveAllListeners();
btn_Use.onClick.AddListener(() =>
{
switch (propType)
{
case PropEnum.none:
break;
case PropEnum.炮塔碎片:
break;
case PropEnum.翅膀碎片:
break;
case PropEnum.战神碎片:
break;
case PropEnum.刮刮卡:
uIManager.ShowAsync(UIPanel.GuaGuaKa);
break;
case PropEnum.改名卡:
break;
case PropEnum.大喇叭:
break;
case PropEnum.技能:
break;
case PropEnum.召唤卡:
break;
default:
break;
}
});
}
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;
propType=(PropEnum)product.type;
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);
});
btn_Use.onClick.RemoveAllListeners();
btn_Use.onClick.AddListener(() =>
{
switch (propType)
{
case PropEnum.none:
break;
case PropEnum.炮塔碎片:
break;
case PropEnum.翅膀碎片:
break;
case PropEnum.战神碎片:
break;
case PropEnum.刮刮卡:
uIManager.ShowAsync(UIPanel.GuaGuaKa);
break;
case PropEnum.改名卡:
break;
case PropEnum.大喇叭:
break;
case PropEnum.技能:
break;
case PropEnum.召唤卡:
break;
default:
break;
}
});
}
});
}
}
}