Class Pooling
A class that makes it easy to pool any object you want. Acts as a drop-in replacement for GameObject.Instantiate, while still reaping the benefits of pooling
This class handles creating ObjectPools for you, so you can just call Instantiate(GameObject) to instantiate a pooled object
Namespace: WeaverCore
Assembly: WeaverCore.dll
Syntax
public static class Pooling
Methods
| Edit this page View SourceCreatePool(GameObject)
Creates a new pool for a prefab
Declaration
public static ObjectPool CreatePool(GameObject prefab)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab | The prefab to create a new pool for |
Returns
Type | Description |
---|---|
ObjectPool | The new pool for the prefab |
CreatePool(PoolableObject)
Creates a new pool for a prefab
Declaration
public static ObjectPool CreatePool(PoolableObject prefab)
Parameters
Type | Name | Description |
---|---|---|
PoolableObject | prefab | The prefab to create a new pool for |
Returns
Type | Description |
---|---|
ObjectPool | The new pool for the prefab |
CreatePool<T>(T)
Creates a new pool for a prefab
Declaration
public static ObjectPool CreatePool<T>(T prefab) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | prefab | The prefab to create a new pool for |
Returns
Type | Description |
---|---|
ObjectPool | The new pool for the prefab |
Type Parameters
Name | Description |
---|---|
T | The type of component on the prefab |
Destroy(GameObject)
Destroys an existing object and returns it to a pool
Declaration
public static void Destroy(GameObject gameObject)
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | The object to destroy |
Destroy(GameObject, float)
Destroys an existing object and returns it to a pool
Declaration
public static void Destroy(GameObject gameObject, float time)
Parameters
Type | Name | Description |
---|---|---|
GameObject | gameObject | The object to destroy |
float | time | The delay before the object is returned to the pool |
Destroy(PoolableObject)
Destroys an existing object and returns it to a pool
Declaration
public static void Destroy(PoolableObject poolableObject)
Parameters
Type | Name | Description |
---|---|---|
PoolableObject | poolableObject | The object to destroy |
Destroy(PoolableObject, float)
Destroys an existing object and returns it to a pool
Declaration
public static void Destroy(PoolableObject poolableObject, float time)
Parameters
Type | Name | Description |
---|---|---|
PoolableObject | poolableObject | The object to destroy |
float | time | The delay before the object is returned to the pool |
Destroy<T>(T)
Destroys an existing object and returns it to a pool
Declaration
public static void Destroy<T>(T component) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | component | The object to destroy |
Type Parameters
Name | Description |
---|---|
T | The type of component from the destroyed object |
Destroy<T>(T, float)
Destroys an existing object and returns it to a pool
Declaration
public static void Destroy<T>(T component, float time) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | component | The object to destroy |
float | time | The delay before the object is returned to the pool |
Type Parameters
Name | Description |
---|---|
T | The type of component from the destroyed object |
Instantiate(GameObject)
Instantiates a pooled object
Declaration
public static GameObject Instantiate(GameObject prefab)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab | The prefab to instantiate from a pool |
Returns
Type | Description |
---|---|
GameObject | Returns a newly instantiated object |
Instantiate(GameObject, Transform)
Instantiates a pooled object
Declaration
public static GameObject Instantiate(GameObject prefab, Transform parent)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab | The prefab to instantiate from a pool |
Transform | parent | The parent of the newly instantiated object |
Returns
Type | Description |
---|---|
GameObject | Returns a newly instantiated object |
Instantiate(GameObject, Transform, bool)
Instantiates a pooled object
Declaration
public static GameObject Instantiate(GameObject prefab, Transform parent, bool instantiateInWorldSpace)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab | The prefab to instantiate from a pool |
Transform | parent | The parent of the newly instantiated object |
bool | instantiateInWorldSpace | Should the object be positioned in world space? If false, it will be positioned relative to the parent |
Returns
Type | Description |
---|---|
GameObject | Returns a newly instantiated object |
Instantiate(GameObject, Vector3, Quaternion)
Instantiates a pooled object
Declaration
public static GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab | The prefab to instantiate from a pool |
Vector3 | position | The position of the newly instantiated object |
Quaternion | rotation | The rotation of the newly instantiated object |
Returns
Type | Description |
---|---|
GameObject | Returns a newly instantiated object |
Instantiate(GameObject, Vector3, Quaternion, Transform)
Instantiates a pooled object
Declaration
public static GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent)
Parameters
Type | Name | Description |
---|---|---|
GameObject | prefab | The prefab to instantiate from a pool |
Vector3 | position | The position of the newly instantiated object |
Quaternion | rotation | The rotation of the newly instantiated object |
Transform | parent | The parent of the newly instantiated object |
Returns
Type | Description |
---|---|
GameObject | Returns a newly instantiated object |
Instantiate<T>(T)
Instantiates a pooled object
Declaration
public static T Instantiate<T>(T prefab) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | prefab | The prefab to instantiate from a pool |
Returns
Type | Description |
---|---|
T | Returns a newly instantiated object |
Type Parameters
Name | Description |
---|---|
T | The component type to get from the instantiated object |
Instantiate<T>(T, Transform)
Instantiates a pooled object
Declaration
public static T Instantiate<T>(T prefab, Transform parent) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | prefab | The prefab to instantiate from a pool |
Transform | parent | The parent of the newly instantiated object |
Returns
Type | Description |
---|---|
T | Returns a newly instantiated object |
Type Parameters
Name | Description |
---|---|
T | The component type to get from the instantiated object |
Instantiate<T>(T, Transform, bool)
Instantiates a pooled object
Declaration
public static T Instantiate<T>(T prefab, Transform parent, bool instantiateInWorldSpace) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | prefab | The prefab to instantiate from a pool |
Transform | parent | The parent of the newly instantiated object |
bool | instantiateInWorldSpace | Should the object be positioned in world space? If false, it will be positioned relative to the parent |
Returns
Type | Description |
---|---|
T | Returns a newly instantiated object |
Type Parameters
Name | Description |
---|---|
T | The component type to get from the instantiated object |
Instantiate<T>(T, Vector3, Quaternion)
Instantiates a pooled object
Declaration
public static T Instantiate<T>(T prefab, Vector3 position, Quaternion rotation) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | prefab | The prefab to instantiate from a pool |
Vector3 | position | The position of the newly instantiated object |
Quaternion | rotation | The rotation of the newly instantiated object |
Returns
Type | Description |
---|---|
T | Returns a newly instantiated object |
Type Parameters
Name | Description |
---|---|
T | The component type to get from the instantiated object |
Instantiate<T>(T, Vector3, Quaternion, Transform)
Instantiates a pooled object
Declaration
public static T Instantiate<T>(T prefab, Vector3 position, Quaternion rotation, Transform parent) where T : Component
Parameters
Type | Name | Description |
---|---|---|
T | prefab | The prefab to instantiate from a pool |
Vector3 | position | The position of the newly instantiated object |
Quaternion | rotation | The rotation of the newly instantiated object |
Transform | parent | The parent of the newly instantiated object |
Returns
Type | Description |
---|---|
T | Returns a newly instantiated object |
Type Parameters
Name | Description |
---|---|
T | The component type to get from the instantiated object |