59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using JetBrains.Annotations;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ShopUiCtrl : SingletonMonoBehaviour<ShopUiCtrl>
|
|
{
|
|
[SerializeField] GameObject itemPrefab;
|
|
[SerializeField] Transform itemContent;
|
|
|
|
GameObjectPool<ShopMenuItem> itemPrefabList;
|
|
|
|
List<ShopMenuItem> onItemPrefabList;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
itemPrefabList = new GameObjectPool<ShopMenuItem>(5, () =>
|
|
{
|
|
var obj = Instantiate(itemPrefab, itemContent);
|
|
obj.SetActive(false);
|
|
var clone = obj.GetComponent<ShopMenuItem>();
|
|
return clone;
|
|
});
|
|
onItemPrefabList = new List<ShopMenuItem>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Dictionary<long, ShopData> 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();
|
|
}
|
|
}
|
|
} |