From 22891bf59032ba88262824255a706d652031384b Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 10 Mar 2022 14:07:40 +0800 Subject: * move folder --- Assets/Scripts/Utils/ListPool.cs | 65 ---------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 Assets/Scripts/Utils/ListPool.cs (limited to 'Assets/Scripts/Utils/ListPool.cs') diff --git a/Assets/Scripts/Utils/ListPool.cs b/Assets/Scripts/Utils/ListPool.cs deleted file mode 100644 index 9819aa48..00000000 --- a/Assets/Scripts/Utils/ListPool.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.Events; - -public static class ListPool -{ - public static List Get() - { - return ListPool.m_ListPool.Get(); - } - - public static void Release(List toRelease) - { - ListPool.m_ListPool.Release(toRelease); - } - - private static readonly ObjectPool> m_ListPool = new ObjectPool>(null, delegate (List l) - { - l.Clear(); - }); -} - -public class ObjectPool where T : new() -{ - private readonly Stack m_Stack = new Stack(); - private readonly UnityAction m_ActionOnGet; - private readonly UnityAction m_ActionOnRelease; - - public int countAll { get; private set; } - public int countActive { get { return countAll - countInactive; } } - public int countInactive { get { return m_Stack.Count; } } - - public ObjectPool(UnityAction actionOnGet, UnityAction actionOnRelease) - { - m_ActionOnGet = actionOnGet; - m_ActionOnRelease = actionOnRelease; - } - - public T Get() - { - T element; - if (m_Stack.Count == 0) - { - element = new T(); - countAll++; - } - else - { - element = m_Stack.Pop(); - } - if (m_ActionOnGet != null) - m_ActionOnGet(element); - return element; - } - - public void Release(T element) - { - if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element)) - Debug.LogError("Internal error. Trying to destroy object that is already released to pool."); - if (m_ActionOnRelease != null) - m_ActionOnRelease(element); - m_Stack.Push(element); - } -} \ No newline at end of file -- cgit v1.1-26-g67d0