using UnityEngine; using System.Collections.Generic; namespace Neatly.UI { public class NParticlePool : MonoBehaviour { private static NParticlePool _instance; public static NParticlePool Instance { get { if (_instance == null) { Init(); } return _instance; } } private List m_Pool = new List(); public static void Init() { if (_instance == null) { GameObject go = new GameObject("~NParticlePool"); _instance = go.AddComponent(); DontDestroyOnLoad(go); } } public EffectImage Create() { EffectImage effectImage; if (m_Pool.Count > 0) { effectImage = m_Pool[m_Pool.Count - 1]; m_Pool.RemoveAt(m_Pool.Count - 1); return effectImage; } GameObject go = new GameObject("NParticle"); effectImage = go.AddComponent(); return effectImage; } public void Recycle(EffectImage effectImage) { effectImage.transform.parent = transform; effectImage.Clear(); m_Pool.Add(effectImage); } } }