Class ObjectPool<T>
Instance pool for objects
Namespace: Unity.XRTools.Utils
Syntax
public class ObjectPool<T>
where T : class, new()
Type Parameters
Name | Description |
---|---|
T | The type of object to manage instances of |
Fields
m_Queue
All objects in the pool
Declaration
protected readonly Queue<T> m_Queue
Field Value
Type | Description |
---|---|
Queue<T> |
Methods
ClearInstance(T)
Implement a clearing function in this in a derived class to have the Recycle(T) method automatically clear the item.
Declaration
protected virtual void ClearInstance(T instance)
Parameters
Type | Name | Description |
---|---|---|
T | instance | The object to return to the pool |
Get()
Get an instance of the object type
Declaration
public virtual T Get()
Returns
Type | Description |
---|---|
T | The object instance |
Recycle(T)
Return an object instance to the pool
Declaration
public void Recycle(T instance)
Parameters
Type | Name | Description |
---|---|---|
T | instance | The instance to return |