首次提交

This commit is contained in:
2026-07-13 18:14:23 +08:00
commit 20d09e4ebb
5293 changed files with 621708 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ToastPool : MonoBehaviour
{
public static ToastPool Instance;
[SerializeField] private Toast toastPrefab; // Toast预制体
[SerializeField] private Transform poolParent; // 对象池中的Toast存放位置
private Queue<Toast> pool = new Queue<Toast>();
private void Awake()
{
Instance = this;
}
// 获取一个Toast
public Toast GetFromPool()
{
if (pool.Count > 0)
{
Toast toast = pool.Dequeue();
toast.gameObject.SetActive(true);
return toast;
}
return Instantiate(toastPrefab, poolParent);
}
// 回收Toast到对象池
public void ReturnToPool(Toast toast)
{
toast.Reset(); // 重置Toast状态
pool.Enqueue(toast); // 回收进队列
}
}