加入很多新内容,这波一块交了
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class itemGetPrefab : MonoBehaviour
|
||||
{
|
||||
[Header("item prefab")]
|
||||
public GameObject itemPrefab;
|
||||
public Transform displayParent;
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user