52 lines
1.3 KiB
C#
Raw Normal View History

2024-12-16 17:25:10 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RewardPanel : MonoBehaviour
{
[SerializeField] private GameObject item;
[SerializeField] private Transform itemParent;
[SerializeField] private List<ItemObj> _itemObjs = new List<ItemObj>();
[SerializeField] private Button close;
private void OnEnable()
{
close.onClick.AddListener(Close);
}
private void OnDisable()
{
close.onClick.RemoveListener(Close);
}
public void SaveData(List<ItemDataNum> itemDatas)
{
foreach (var i in _itemObjs)
{
i.gameObject.SetActive(false);
}
for (int i = 0; i < itemDatas.Count; i++)
{
if (i>=_itemObjs.Count)
{
var obj = Instantiate(item, itemParent);
_itemObjs.Add(obj.GetComponent<ItemObj>());
obj.SetActive(true);
obj.GetComponent<ItemObj>().SetData(itemDatas[i].id,itemDatas[i].num);
}
else
{
_itemObjs[i].gameObject.SetActive(true);
_itemObjs[i].SetData(itemDatas[i].id,itemDatas[i].num);
}
}
}
private void Close()
{
gameObject.SetActive(false);
}
}