DoopelPonger
Classes | Public Member Functions | List of all members
CoopObjectPooler Class Reference

Class used to hold and dish out allocated objects. More...

Inheritance diagram for CoopObjectPooler:
Inheritance graph
[legend]
Collaboration diagram for CoopObjectPooler:
Collaboration graph
[legend]

Classes

class  IObjectPoolerItem
 Any object that implements this interface can be pooled in the object pooler. More...
 

Public Member Functions

void Awake ()
 Initialize data structures to store the unused objects. More...
 
GetObjectFromCustomKeyPool< T > (T poolItem)
 Takes the first item off the unusues queue or creates a new object of type T. More...
 
void ReturnObjectToCustomKeyPool< T > (T returnObject)
 Takes the IObjectPoolerItem, deactivates it, and places it in the unused queue. More...
 
void PreAllocatePool< T > (T original, int copies)
 Given the prefab original object, pre store unused copies of objects in the queue. More...
 
GetMonoBehaviour< T > (T original, int numberToPreAllocate)
 Get the MonoBehaviour from the unused queue. If the queue never existed, create one with the size requested. More...
 
T [] GetMonoBehaviour< T > (T[] originals)
 Iterate through the list of MonoBehaviours and get/create an instance from the appropirate unused queue. More...
 
GetMonoBehaviour< T > (T original)
 Get the MonoBehaviour from the unused queue. More...
 
ScriptableObject GetScriptableObject (System.Type scriptableType)
 Get the ScriptableObject from the unused queue. More...
 
GetScriptableObject< T > ()
 Get the ScriptableObject from the unused queue. More...
 
GetObject< T > (T original)
 Get the Unity Object from the unused queue. More...
 
void ReturnObject< T > (T returnObject)
 
void ReturnMonoBehaviour< T > (T returnObject)
 
void ReturnScriptableObject< T > (T returnObject)
 

Detailed Description

Class used to hold and dish out allocated objects.

If the object being asked for does not exist, then one will be created and then returned. The original implementation of this object would save/return objects based on the System.Type. However this is not ideal in cases where the underlying object is the same but the properties of the object are different (like objects that hold audio information). So at the end of developement I added the IObjectPoolerItem interface so that similar objects could be pooled without getting their properties switched around.

Member Function Documentation

◆ Awake()

void CoopObjectPooler.Awake ( )

Initialize data structures to store the unused objects.

◆ GetMonoBehaviour< T >() [1/3]

T CoopObjectPooler.GetMonoBehaviour< T > ( original,
int  numberToPreAllocate 
)

Get the MonoBehaviour from the unused queue. If the queue never existed, create one with the size requested.

Parameters
originalThe object to be created/returned from the object pooler.
numberToPreAllocateHow big the holding queue should be if it doesn't already exist for the original.
Returns
The object that should be used by the caller.
Type Constraints
T :MonoBehaviour 

◆ GetMonoBehaviour< T >() [2/3]

T [] CoopObjectPooler.GetMonoBehaviour< T > ( T []  originals)

Iterate through the list of MonoBehaviours and get/create an instance from the appropirate unused queue.

Parameters
originalsList of MonoBehaviours to return instances of.
Returns
The list of new objects. The returned objects will be in the same order as the originals passed in.
Type Constraints
T :MonoBehaviour 

◆ GetMonoBehaviour< T >() [3/3]

T CoopObjectPooler.GetMonoBehaviour< T > ( original)

Get the MonoBehaviour from the unused queue.

Parameters
originalThe object to be created/returned from the object pooler.
Returns
The object that should be used by the caller.
Type Constraints
T :MonoBehaviour 

◆ GetObject< T >()

T CoopObjectPooler.GetObject< T > ( original)

Get the Unity Object from the unused queue.

Parameters
originalThe object to be created/returned from the object pooler.
Returns
The object that should be used by the caller.
Type Constraints
T :Object 

◆ GetObjectFromCustomKeyPool< T >()

T CoopObjectPooler.GetObjectFromCustomKeyPool< T > ( poolItem)

Takes the first item off the unusues queue or creates a new object of type T.

Parameters
poolItemPrefab of the object that should be returned, must be of type IObjectPoolerItem so it finds the item to return by the GetObjectPoolerKey identifier.
Returns
The object to be used by the caller object.
Type Constraints
T :MonoBehaviour 
T :IObjectPoolerItem 

◆ GetScriptableObject()

ScriptableObject CoopObjectPooler.GetScriptableObject ( System.Type  scriptableType)

Get the ScriptableObject from the unused queue.

Parameters
scriptableTypeThe type of the ScriptableObject to return
Returns
The object that should be used by the caller.

◆ GetScriptableObject< T >()

Get the ScriptableObject from the unused queue.

Parameters
TThe type of the ScriptableObject to return
Returns
The object that should be used by the caller.
Type Constraints
T :ScriptableObject 

◆ PreAllocatePool< T >()

void CoopObjectPooler.PreAllocatePool< T > ( original,
int  copies 
)

Given the prefab original object, pre store unused copies of objects in the queue.

Parameters
originalBlueprint object that will be created and placed in the unused pool.
copiesNumber of new objects placed unused pool.
Type Constraints
T :MonoBehaviour 

◆ ReturnMonoBehaviour< T >()

void CoopObjectPooler.ReturnMonoBehaviour< T > ( returnObject)
Parameters
returnedObjectMonoBehaviour to set unactive and place back into the unused queue.
Type Constraints
T :MonoBehaviour 

◆ ReturnObject< T >()

void CoopObjectPooler.ReturnObject< T > ( returnObject)
Parameters
returnObjectUnity Object to place back into the unusused queue.
Type Constraints
T :Object 

◆ ReturnObjectToCustomKeyPool< T >()

void CoopObjectPooler.ReturnObjectToCustomKeyPool< T > ( returnObject)

Takes the IObjectPoolerItem, deactivates it, and places it in the unused queue.

Parameters
returnObjectGameObject that should be deactived and placed in the unused queue.
Type Constraints
T :MonoBehaviour 
T :IObjectPoolerItem 

◆ ReturnScriptableObject< T >()

void CoopObjectPooler.ReturnScriptableObject< T > ( returnObject)
Parameters
returnObjectScriptableObject to be placed back in the unused queue.
Type Constraints
T :ScriptableObject 

The documentation for this class was generated from the following file: