Class ObjectPool
Inheritance
Inherited Members
Namespace: GameKit.Dependencies.Utilities.ObjectPooling
Assembly: GameKit.Dependencies.dll
Syntax
public class ObjectPool : MonoBehaviour
Methods
__Reset(Boolean)
Destroys all stored and optionally retrieved objects. Race conditions may be created by this coroutine if trying to retrieve or store objects before it finishes executing.
Declaration
public IEnumerator __Reset(bool destroyActive)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | destroyActive | True to also destroy active retrieved gameObjects. False will erase active objects from memory, but not destroy them. |
Returns
| Type | Description |
|---|---|
| System.Collections.IEnumerator |
Retrieve(GameObject)
Returns a pooled object of the specified prefab.
Declaration
public static GameObject Retrieve(GameObject poolObject)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | poolObject | Prefab to retrieve. |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject |
Retrieve(GameObject, Transform, Boolean)
Returns a pooled object of the specified prefab.
Declaration
public static GameObject Retrieve(GameObject poolObject, Transform parent, bool instantiateInWorldSpace = true)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | poolObject | Prefab to retrieve. |
| UnityEngine.Transform | parent | Parent to attach the retrieved prefab to. |
| System.Boolean | instantiateInWorldSpace | Use true when assigning a parent Object to maintain the world position of the Object, instead of setting its position relative to the new parent. Pass false to set the Object's position relative to its new parent. |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject |
Retrieve(GameObject, Vector3, Quaternion)
Returns a pooled object of the specified prefab.
Declaration
public static GameObject Retrieve(GameObject poolObject, Vector3 position, Quaternion rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | poolObject | Prefab to retrieve. |
| UnityEngine.Vector3 | position | Position for the retrieved object. |
| UnityEngine.Quaternion | rotation | Orientation for the retrieved object. |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject |
Retrieve(GameObject, Vector3, Quaternion, Transform)
Returns a pooled object of the specified prefab.
Declaration
public GameObject Retrieve(GameObject poolObject, Vector3 position, Quaternion rotation, Transform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | poolObject | Prefab to retrieve. |
| UnityEngine.Vector3 | position | Position for the retrieved object. |
| UnityEngine.Quaternion | rotation | Orientation for the retrieved object. |
| UnityEngine.Transform | parent | Transform to parent the retrieved object to. |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject |
Retrieve<T>(GameObject)
Returns a pooled object of the specified prefab.
Declaration
public static T Retrieve<T>(GameObject prefab)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | prefab | Prefab to retrieve. |
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T |
Retrieve<T>(GameObject, Transform, Boolean)
Returns a pooled object of the specified prefab.
Declaration
public static T Retrieve<T>(GameObject prefab, Transform parent, bool instantiateInWorldSpace = true)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | prefab | Prefab to retrieve. |
| UnityEngine.Transform | parent | Parent to attach the retrieved prefab to. |
| System.Boolean | instantiateInWorldSpace | Use true when assigning a parent Object to maintain the world position of the Object, instead of setting its position relative to the new parent. Pass false to set the Object's position relative to its new parent. |
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T |
Retrieve<T>(GameObject, Vector3, Quaternion)
Returns a pooled object of the specified prefab.
Declaration
public static T Retrieve<T>(GameObject prefab, Vector3 position, Quaternion rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | prefab | Prefab to retrieve. |
| UnityEngine.Vector3 | position | Position for the retrieved object. |
| UnityEngine.Quaternion | rotation | Orientation for the retrieved object. |
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T |
Retrieve<T>(GameObject, Vector3, Quaternion, Transform)
Returns a pooled object of the specified prefab.
Declaration
public static T Retrieve<T>(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | prefab | Prefab to retrieve. |
| UnityEngine.Vector3 | position | Position for the retrieved object. |
| UnityEngine.Quaternion | rotation | Orientation for the retrieved object. |
| UnityEngine.Transform | parent | Transform to parent the retrieved object to. |
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T |
RetrieveInternal(GameObject, Transform, Boolean)
Declaration
public GameObject RetrieveInternal(GameObject poolObject, Transform parent, bool instantiateInWorldSpace = true)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | poolObject | |
| UnityEngine.Transform | parent | |
| System.Boolean | instantiateInWorldSpace |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject |
Store(GameObject, Boolean)
Returns an object to it's pool.
Declaration
public static void Store(GameObject instantiatedObject, bool parentPooler = true)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | instantiatedObject | |
| System.Boolean | parentPooler | True to set the objects parent as the ObjectPooler. |
Store(GameObject, Single, Boolean)
Returns an object to it's pool.
Declaration
public static void Store(GameObject instantiatedObject, float delay, bool parentPooler = true)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | instantiatedObject | |
| System.Single | delay | |
| System.Boolean | parentPooler | True to set the objects parent as the ObjectPooler. |