[TASK] Initial commit with basic product setup
This commit is contained in:
43
Assets/Mapbox SDK/Mapbox/Unity/Utilities/ObjectPool.cs
Normal file
43
Assets/Mapbox SDK/Mapbox/Unity/Utilities/ObjectPool.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace Mapbox.Unity.MeshGeneration.Data
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectPool<T>
|
||||
{
|
||||
private Queue<T> _objects;
|
||||
private Func<T> _objectGenerator;
|
||||
|
||||
public ObjectPool(Func<T> objectGenerator)
|
||||
{
|
||||
if (objectGenerator == null) throw new ArgumentNullException("objectGenerator");
|
||||
_objects = new Queue<T>();
|
||||
_objectGenerator = objectGenerator;
|
||||
}
|
||||
|
||||
public T GetObject()
|
||||
{
|
||||
if (_objects.Count > 0)
|
||||
return _objects.Dequeue();
|
||||
return _objectGenerator();
|
||||
}
|
||||
|
||||
public void Put(T item)
|
||||
{
|
||||
_objects.Enqueue(item);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_objects.Clear();
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetQueue()
|
||||
{
|
||||
return _objects;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user