using JetBrains.Annotations; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ShopUiCtrl : SingletonMonoBehaviour { [SerializeField] GameObject itemPrefab; [SerializeField] Transform itemContent; GameObjectPool itemPrefabList; List onItemPrefabList; protected override void OnAwake() { itemPrefabList = new GameObjectPool(5, () => { var obj = Instantiate(itemPrefab, itemContent); obj.SetActive(false); var clone = obj.GetComponent(); return clone; }); onItemPrefabList = new List(); } private void OnEnable() { Dictionary shopDatas = Statics.excelDatas.shopData; if(shopDatas.Count != onItemPrefabList.Count) { foreach (var item in onItemPrefabList) { item.gameObject.SetActive(false); itemPrefabList.push(item); } onItemPrefabList.Clear(); foreach (var item in shopDatas) { ShopMenuItem shopMenuItem = itemPrefabList.pop(); shopMenuItem.Set(item.Value); shopMenuItem.gameObject.SetActive(true); onItemPrefabList.Add(shopMenuItem); } if (onItemPrefabList.Count != 0) onItemPrefabList[0].SelectButton(); } } public void SelectShopMenu() { for(int n = 0; n < onItemPrefabList.Count; n++) { onItemPrefabList[n].ChangeButton(); } } }