74 lines
1.6 KiB
C#
74 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
|
|
public class itemGetPrefab : MonoBehaviour
|
|
{
|
|
[Header("item prefab")]
|
|
public GameObject itemPrefab;
|
|
public Transform displayParent;
|
|
|
|
[Header("rarity")]
|
|
public ItemRarityColorConfigSO rarityColorConfig;
|
|
|
|
[Header("btn")]
|
|
public Button close;
|
|
|
|
private readonly List<GameObject> spawnedItems = new List<GameObject>();
|
|
|
|
private void Awake()
|
|
{
|
|
if (close != null)
|
|
{
|
|
close.onClick.RemoveListener(CloseSelf);
|
|
close.onClick.AddListener(CloseSelf);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (close != null)
|
|
{
|
|
close.onClick.RemoveListener(CloseSelf);
|
|
}
|
|
}
|
|
|
|
public void ClearItems()
|
|
{
|
|
for (int i = 0; i < spawnedItems.Count; i++)
|
|
{
|
|
if (spawnedItems[i] != null)
|
|
{
|
|
Destroy(spawnedItems[i]);
|
|
}
|
|
}
|
|
|
|
spawnedItems.Clear();
|
|
|
|
if (displayParent != null)
|
|
{
|
|
for (int i = displayParent.childCount - 1; i >= 0; i--)
|
|
{
|
|
Destroy(displayParent.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public get_item_prefab AddItem()
|
|
{
|
|
if (itemPrefab == null || displayParent == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
GameObject instance = Instantiate(itemPrefab, displayParent);
|
|
spawnedItems.Add(instance);
|
|
return instance.GetComponent<get_item_prefab>();
|
|
}
|
|
|
|
public void CloseSelf()
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|