加入很多新内容,这波一块交了

This commit is contained in:
2026-04-08 20:53:41 +08:00
parent d9376833b6
commit 85dfff28dd
128 changed files with 14546 additions and 474 deletions
+70
View File
@@ -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);
}
}