diff --git a/TheStrongestSnail/Assets/Scenes/logo.unity b/TheStrongestSnail/Assets/Scenes/logo.unity index a3d6025..93afb5d 100644 --- a/TheStrongestSnail/Assets/Scenes/logo.unity +++ b/TheStrongestSnail/Assets/Scenes/logo.unity @@ -3616,7 +3616,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: 712.31714, y: -1387.5} + m_AnchoredPosition: {x: 686, y: -1387.5} m_SizeDelta: {x: 1018, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1071890038 diff --git a/TheStrongestSnail/Assets/Scripts/Scene_main/Scene_main_jiekou.cs b/TheStrongestSnail/Assets/Scripts/Scene_main/Scene_main_jiekou.cs index 6131805..9d7d17a 100644 --- a/TheStrongestSnail/Assets/Scripts/Scene_main/Scene_main_jiekou.cs +++ b/TheStrongestSnail/Assets/Scripts/Scene_main/Scene_main_jiekou.cs @@ -26,7 +26,7 @@ public class Scene_main_jiekou :Base instance = this; //testLogo(); - //getPlayerInfo(); + getPlayerInfo(); // getShopInfo(); } diff --git a/TheStrongestSnail/Assets/Scripts/Scene_shop/itemInfo.cs b/TheStrongestSnail/Assets/Scripts/Scene_shop/itemInfo.cs index e527b61..e5f8028 100644 --- a/TheStrongestSnail/Assets/Scripts/Scene_shop/itemInfo.cs +++ b/TheStrongestSnail/Assets/Scripts/Scene_shop/itemInfo.cs @@ -11,45 +11,29 @@ public class itemInfo : MonoBehaviour [Header("物品名的TextPro")] public TextMeshProUGUI nameText; [Header("物品价格的TextPro")] - public TextMeshProUGUI priceText; - - [Header("可以按下的按钮")] - public Button btn; - [Header("按下按钮显示的界面")] - public GameObject prefab; - - + public TextMeshProUGUI priceText; private int id;//item id - // Start is called before the first frame update - void Start() - { - btn.onClick.AddListener(()=> { - - GameObject.Instantiate(prefab,GameObject.Find("Canvas").transform); - }); - } - - public void init(int id) - { - this.id = id; - } + + public void initShow(int id, Sprite icon, string name, string price) { this.id = id; iconImage.sprite = icon; nameText.text = name; - priceText.text = price; + priceText.text = "¥" + price; } public void initShow(int id, string name, string price) { + this.id = id; nameText.text = name; - priceText.text = price; + priceText.text = "¥"+price; + } } diff --git a/TheStrongestSnail/Assets/Scripts/Scene_shop/shopPanel.cs b/TheStrongestSnail/Assets/Scripts/Scene_shop/shopPanel.cs index b95a996..59a9548 100644 --- a/TheStrongestSnail/Assets/Scripts/Scene_shop/shopPanel.cs +++ b/TheStrongestSnail/Assets/Scripts/Scene_shop/shopPanel.cs @@ -2,18 +2,51 @@ using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; +using UnityEngine.UI; using DG.Tweening; public class shopPanel: ui_huodong { public List itemInfos = new List(); + [Header("商店的详细面板")] + public GameObject Panel; + public override void Start() + { + base.Start(); + initShop(); + } void initShop() { int index = 0; + + // 遍历 shopItemDic 中的每个商品,并更新 itemInfos 中的显示项 foreach (KeyValuePair go in Scene_main_jiekou.instance.shopItemDic) { - itemInfos[index].initShow(go.Value.ProductId,go.Value.ProductName,go.Value.ProductPic.ToString()); + + // 如果 index 超过 itemInfos 的大小,表示字典的元素比 itemInfos 更多 + if (index >= itemInfos.Count) + { + Debug.LogWarning("shopItemDic contains more items than itemInfos. Some items will not be shown."); + break; // 如果字典中的元素多于 itemInfos 中的项,停止遍历 + } + + // 更新当前 itemInfo 显示项 + itemInfos[index].gameObject.SetActive(true); // 显示当前项 + itemInfos[index].initShow(go.Value.ProductId, go.Value.ProductName,go.Value.Price.ToString()); + itemInfos[index].GetComponent