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 _itemObjs = new List(); [SerializeField] private Button close; private void OnEnable() { close.onClick.AddListener(Close); } private void OnDisable() { close.onClick.RemoveListener(Close); } public void SaveData(List 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()); obj.SetActive(true); obj.GetComponent().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); } }