fix:1、添加项目
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlowerPower
|
||||
{
|
||||
public static class ListPool<T>
|
||||
{
|
||||
private static readonly ObjectPool<List<T>> s_ListPool = new(null, Clear);
|
||||
|
||||
private static void Clear(List<T> l)
|
||||
{
|
||||
l.Clear();
|
||||
}
|
||||
|
||||
public static List<T> Get()
|
||||
{
|
||||
return s_ListPool.Get();
|
||||
}
|
||||
|
||||
public static void Release(List<T> toRelease)
|
||||
{
|
||||
s_ListPool.Release(toRelease);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2d8e7c78227e3f43bffd43d95be542d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlowerPower
|
||||
{
|
||||
public class ObjectPool<T> where T : new()
|
||||
{
|
||||
private Stack<T> m_Stack = new();
|
||||
|
||||
private Action<T> m_ActionOnNew;
|
||||
private Action<T> m_ActionOnGet;
|
||||
private Action<T> m_ActionOnRelease;
|
||||
|
||||
public int CountAll { get; private set; }
|
||||
|
||||
public ObjectPool()
|
||||
{
|
||||
}
|
||||
|
||||
public ObjectPool(Action<T> actionOnGet, Action<T> actionOnRelease)
|
||||
{
|
||||
m_ActionOnGet = actionOnGet;
|
||||
m_ActionOnRelease = actionOnRelease;
|
||||
}
|
||||
|
||||
public T Get()
|
||||
{
|
||||
T element;
|
||||
if (m_Stack.Count == 0)
|
||||
{
|
||||
element = new T();
|
||||
CountAll++;
|
||||
|
||||
if (m_ActionOnNew != null)
|
||||
{
|
||||
m_ActionOnNew(element);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
element = m_Stack.Pop();
|
||||
}
|
||||
|
||||
if (m_ActionOnGet != null)
|
||||
m_ActionOnGet(element);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public void Release(T element)
|
||||
{
|
||||
if (m_ActionOnRelease != null)
|
||||
{
|
||||
m_ActionOnRelease(element);
|
||||
}
|
||||
|
||||
m_Stack.Push(element);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
m_Stack.Clear();
|
||||
m_Stack = null;
|
||||
|
||||
m_ActionOnNew = null;
|
||||
m_ActionOnGet = null;
|
||||
m_ActionOnRelease = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a28a8a5d75b01a048af3d789b3c0f265
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user