Class MasterObjectPooler
MasterObjectPooler manages various ObjectPools. By using a MasterObjectPooler, you can perform a large variety of pool operations with a named string reference instead of requiring an object reference to the ObjectPool. Furthermore, initialization of the pools is handled by the MOP. Pools can be added either via the inspector or at runtime.
Inheritance
Namespace: QFSW.MOP2
Assembly: QFSW.MOP2.dll
Syntax
public class MasterObjectPooler : MonoBehaviour
Properties
| Improve this Doc View SourceInstance
Singleton reference to the MOP. Only valid and set if the singleton option is enabled for the MOP.
Declaration
public static MasterObjectPooler Instance { get; }
Property Value
| Type | Description |
|---|---|
| MasterObjectPooler |
Item[String]
Retrieves/adds a pool.
Declaration
public ObjectPool this[string poolName] { get; set; }
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to retrieve/add. |
Property Value
| Type | Description |
|---|---|
| ObjectPool | The retrieved pool. |
Methods
| Improve this Doc View SourceAddPool(ObjectPool)
Adds an ObjectPool to the MasterObjectPooler and initializes it.
Declaration
public void AddPool(ObjectPool pool)
Parameters
| Type | Name | Description |
|---|---|---|
| ObjectPool | pool | The ObjectPool to add to the MasterObjectPooler. |
AddPool(String, ObjectPool)
Adds an ObjectPool to the MasterObjectPooler and initializes it.
Declaration
public void AddPool(string poolName, ObjectPool pool)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | Override for the named string reference to use for this pool. By default uses the ObjectPool's name. |
| ObjectPool | pool | The ObjectPool to add to the MasterObjectPooler. |
Destroy(IEnumerable<GameObject>, String)
Forcibly destroys a collection of objects and does not return them to a pool.
Declaration
public void Destroy(IEnumerable<GameObject> objs, string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<UnityEngine.GameObject> | objs | The objects to destroy. |
| String | poolName | The name of the pool that the objects belonged to. |
Destroy(GameObject)
Forcibly destroys the object and does not return it to a pool.
Declaration
public void Destroy(GameObject obj)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | obj | The object to destroy. |
Destroy(GameObject, String)
Forcibly destroys the object and does not return it to a pool.
Declaration
public void Destroy(GameObject obj, string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | obj | The object to destroy. |
| String | poolName | The name of the pool that the object belonged to. |
DestroyAllPools()
Destroys every pool, purging all of their contents then removing them from the MasterObjectPooler.
Declaration
public void DestroyAllPools()
DestroyPool(String)
Destroys a specified pool, purging its contents and removing it from the MasterObjectPooler.
Declaration
public void DestroyPool(string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The pool to destroy. |
GetAllActiveObjects(String)
Gets all active objects in the specified pool.
Declaration
public IEnumerable<GameObject> GetAllActiveObjects(string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to populate. |
Returns
| Type | Description |
|---|---|
| IEnumerable<UnityEngine.GameObject> | The active objects. |
GetObject(String)
Gets an object from the specified pool.
Declaration
public GameObject GetObject(string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to get an object from. |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject | The retrieved object. |
GetObject(String, Vector3)
Gets an object from the specified pool.
Declaration
public GameObject GetObject(string poolName, Vector3 position)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to get an object from. |
| UnityEngine.Vector3 | position | The position to set the object to. |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject | The retrieved object. |
GetObject(String, Vector3, Quaternion)
Gets an object from the specified pool.
Declaration
public GameObject GetObject(string poolName, Vector3 position, Quaternion rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to get an object from. |
| UnityEngine.Vector3 | position | The position to set the object to. |
| UnityEngine.Quaternion | rotation | The rotation to set the object to. |
Returns
| Type | Description |
|---|---|
| UnityEngine.GameObject | The retrieved object. |
GetObjectComponent<T>(String)
Gets an object from the specified pool, and then retrieves the specified component using a cache to improve performance. Note: this should not be used if multiple components of the same type exist on the object, or if the component will be dynamically removed/added at runtime.
Declaration
public T GetObjectComponent<T>(string poolName)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to get the component from. |
Returns
| Type | Description |
|---|---|
| T | The retrieved component. |
Type Parameters
| Name | Description |
|---|---|
| T | The component type to get. |
GetObjectComponent<T>(String, Vector3)
Gets an object from the specified pool, and then retrieves the specified component using a cache to improve performance. Note: this should not be used if multiple components of the same type exist on the object, or if the component will be dynamically removed/added at runtime.
Declaration
public T GetObjectComponent<T>(string poolName, Vector3 position)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to get the component from. |
| UnityEngine.Vector3 | position | The position to set the object to. |
Returns
| Type | Description |
|---|---|
| T | The retrieved component. |
Type Parameters
| Name | Description |
|---|---|
| T | The component type to get. |
GetObjectComponent<T>(String, Vector3, Quaternion)
Gets an object from the specified pool, and then retrieves the specified component using a cache to improve performance. Note: this should not be used if multiple components of the same type exist on the object, or if the component will be dynamically removed/added at runtime.
Declaration
public T GetObjectComponent<T>(string poolName, Vector3 position, Quaternion rotation)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to get the component from. |
| UnityEngine.Vector3 | position | The position to set the object to. |
| UnityEngine.Quaternion | rotation | The rotation to set the object to. |
Returns
| Type | Description |
|---|---|
| T | The retrieved component. |
Type Parameters
| Name | Description |
|---|---|
| T | The component type to get. |
GetPool(String)
Retrieves a pool.
Declaration
public ObjectPool GetPool(string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to retrieve. |
Returns
| Type | Description |
|---|---|
| ObjectPool | The retrieved pool. |
Populate(String, Int32, PopulateMethod)
Populates the specified pool with the specified number of objects, so that they do not need instantiating later.
Declaration
public void Populate(string poolName, int quantity, PopulateMethod method = PopulateMethod.Set)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to populate. |
| Int32 | quantity | The number of objects to populate it with. |
| PopulateMethod | method | The population mode. |
Purge(String)
Destroys every object in the specified pool, both alive and pooled.
Declaration
public void Purge(string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool to populate. |
PurgeAll()
Destroys every object in every pool, both alive and pooled.
Declaration
public void PurgeAll()
Release(IEnumerable<GameObject>, String)
Releases a collection of objects and returns them back to the specified pool, effectively 'destroying' them from the scene.
Declaration
public void Release(IEnumerable<GameObject> objs, string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<UnityEngine.GameObject> | objs | the objects to release. |
| String | poolName | The name of the pool to return the objects to. |
Release(GameObject, String)
Releases an object and returns it back to the specified pool, effectively 'destroying' it from the scene. Pool equivalent of Destroy.
Declaration
public void Release(GameObject obj, string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.GameObject | obj | The object to release. |
| String | poolName | The name of the pool to return the object to. |
ReleaseAll(String)
Releases every active object in the specified pool.
Declaration
public void ReleaseAll(string poolName)
Parameters
| Type | Name | Description |
|---|---|---|
| String | poolName | The name of the pool. |
ReleaseAllInAllPools()
Releases every active object in every pool.
Declaration
public void ReleaseAllInAllPools()