using System.Collections.Generic; using System.Linq; using Lean.Pool; using NaughtyAttributes; using UnityEngine; using UnityEngine.Serialization; namespace SLSUtilities.General.LeanPoolAssistance { public class PooledObject : MonoBehaviour, IPoolable { [FormerlySerializedAs("autoDespawn")] [Tooltip("是否在生成后定时自动回收")] public bool isAutoDespawn = true; [ShowIf("isAutoDespawn")][Tooltip("自动回收时间")] public float autoDespawnTime = 1; private List children; public void OnSpawn() { children = GetComponentsInChildren().ToList(); children.Remove(this); children.ForEach(child => child.OnSpawn()); if (isAutoDespawn) { LeanPool.Despawn(gameObject, autoDespawnTime); } } public void OnDespawn() { children.ForEach(child => child.OnDespawn()); } } }