namespace NRKernal
{
using System;
using System.Collections.Generic;
using UnityEngine;
/// An object pool.
public class ObjectPool
{
/// Dictionary of cache pools.
private Dictionary> m_CachePoolDict = new Dictionary>();
/// Number of initializes.
public int InitCount = 100;
/// Expansions this object.
/// Generic type parameter.
public void Expansion() where T : new()
{
var queue = GetQueue();
for (int i = 0; i < InitCount; i++)
{
T data = new T();
queue.Enqueue(data);
}
}
/// Gets the get.
/// Generic type parameter.
/// A T.
public T Get() where T : new()
{
var queue = GetQueue();
if (queue.Count == 0)
{
Expansion();
}
return (T)queue.Dequeue();
}
/// Puts the given data.
/// Generic type parameter.
/// The data.
public void Put(T data) where T : new()
{
var queue = GetQueue();
queue.Enqueue(data);
}
/// Gets the queue.
/// Generic type parameter.
/// The queue.
private Queue