47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ShopUiCtrl : SingletonMonoBehaviour<ShopUiCtrl>
|
|
{
|
|
[SerializeField] GameObject itemPrefab;
|
|
[SerializeField] Transform itemContent;
|
|
|
|
[SerializeField] GameObject[] shopInfo;
|
|
[SerializeField] Transform shopInfoContent;
|
|
|
|
[SerializeField] Sprite[] golds;
|
|
public Sprite getGolds(int index) { return golds[index]; }
|
|
|
|
List<ShopMenuItem> onItemPrefabList;
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
onItemPrefabList = new List<ShopMenuItem>();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
Dictionary<int, ShopData> shopDatas = Statics.excelDatas.shopData;
|
|
if(shopDatas.Count != onItemPrefabList.Count)
|
|
{
|
|
foreach (var item in shopDatas)
|
|
{
|
|
ShopMenuItem shopMenuItem = Instantiate(itemPrefab, itemContent).GetComponent<ShopMenuItem>();
|
|
GameObject type = Instantiate(shopInfo[item.Value.image_type == eImageType.bigImage ? 0 : 1], shopInfoContent);
|
|
shopMenuItem.Set(item.Value, type);
|
|
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();
|
|
}
|
|
}
|
|
} |