UnityEssentials
Small but useful tools and features for Unity
Classes | Public Member Functions | Public Attributes | Properties | Private Member Functions | Private Attributes | List of all members
UnityEngine.PoolEssentials Class Reference

Allows GameObjects pooling by reusing pre-instantiated GameObjects More...

Collaboration diagram for UnityEngine.PoolEssentials:
Collaboration graph

Classes

class  DefaultPositionAndRotation
 Class to handle the default position and rotation where the objects are first instantiated More...
 

Public Member Functions

 PoolEssentials ()
 Creates a Pool instance. More...
 
 PoolEssentials (GameObject[] baseObjects, int size, bool instantiateAllAtCreation=false, bool randomInstantiationSequence=false, int intantiationRandomizationSeed=-1)
 Creates a Pool instance. More...
 
 PoolEssentials (GameObject baseObject, int size, bool instantiateAllAtCreation=false)
 Creates a Pool instance. More...
 
 PoolEssentials (GameObject[] baseObjects, int size, Vector3 instantiationPosition, Quaternion instantiationRotation, bool instantiateAllAtCreation=false, bool randomInstantiationSequence=false, int intantiationRandomizationSeed=-1)
 Creates a Pool instance. More...
 
GameObject Spawn (Vector3 position, Quaternion rotation, Vector3 scale, Transform parent=null)
 Activates an object from the pool. More...
 
void Load (int quantity, Transform parent=null)
 Loads an objet to be later activated/used. More...
 
GameObject Disable (GameObject gameObject)
 Disables the given gameObject if it belongs to the pool. More...
 
GameObject Disable (int gameObjectIndexInPool)
 Disables the gameObject in the given index More...
 

Public Attributes

GameObject[] baseObjects = new GameObject[1]
 The prefabs of the GameObjects to be spawned for the pool. More...
 
bool randomInstantiationSequence = false
 Should the selection of the next base object to instantiate be random? If false, the selection will be made in order looping through the baseObjects array. More...
 
int size = 10
 The size of the pool. How many referenced objects it han have. More...
 

Properties

int activeIndex [get, private set]
 The index of the next GameObject to be activated/spawned. More...
 
int nextBaseObjectIndex [get, private set]
 The index of the base object that is going to be instantiated next. More...
 

Private Member Functions

GameObject InstantiateNewAt (int index, Transform parent=null)
 Instantiates an object for the pool. More...
 
GameObject GetNextBaseObjectToInstantiate (bool register)
 Returns the next BaseObject to be spawned More...
 

Private Attributes

List< GameObject > referencedObjects = new List<GameObject>()
 A reference to the instantiated GameObjects linked to the pool. More...
 
RandomEssentials randomEssentialsInstantiation = new RandomEssentials()
 The randomness generator object used to choose the next base object to instantiate. More...
 
DefaultPositionAndRotation defaultPositionAndRotation = new DefaultPositionAndRotation()
 The default position and rotation where the objects are first instantiated More...
 

Detailed Description

Allows GameObjects pooling by reusing pre-instantiated GameObjects

Definition at line 9 of file PoolEssentials.cs.

Constructor & Destructor Documentation

◆ PoolEssentials() [1/4]

UnityEngine.PoolEssentials.PoolEssentials ( )

Creates a Pool instance.

Definition at line 52 of file PoolEssentials.cs.

◆ PoolEssentials() [2/4]

UnityEngine.PoolEssentials.PoolEssentials ( GameObject[]  baseObjects,
int  size,
bool  instantiateAllAtCreation = false,
bool  randomInstantiationSequence = false,
int  intantiationRandomizationSeed = -1 
)

Creates a Pool instance.

Parameters
baseObjectsThe object that will be instantiated by the pool.
sizeThe maximum number of objects that can be instantiated at the same time.
instantiateAllAtCreationIf the pool should instantiate all the objects in the scene right away (true) or if they should be instantiated when they are needed (false, default value).
randomInstantiationSequenceIf false, the objects will be instantiated in the appearing order in the 'baseObjects array. If true, the order of instantiation of the pooled objects is going to be random.
intantiationRandomizationSeedThe seed used to randomly pick the baseObjects in the first instantiation process

Definition at line 67 of file PoolEssentials.cs.

Here is the call graph for this function:

◆ PoolEssentials() [3/4]

UnityEngine.PoolEssentials.PoolEssentials ( GameObject  baseObject,
int  size,
bool  instantiateAllAtCreation = false 
)

Creates a Pool instance.

Parameters
baseObjectThe object that will be instantiated by the pool.
sizeThe maximum number of objects that can be instantiated at the same time.
instantiateAllAtCreationIf the pool should instantiate all the objects in the scene right away (true) or if they should be instantiated when they are needed (false, default value).

Definition at line 89 of file PoolEssentials.cs.

Here is the call graph for this function:

◆ PoolEssentials() [4/4]

UnityEngine.PoolEssentials.PoolEssentials ( GameObject[]  baseObjects,
int  size,
Vector3  instantiationPosition,
Quaternion  instantiationRotation,
bool  instantiateAllAtCreation = false,
bool  randomInstantiationSequence = false,
int  intantiationRandomizationSeed = -1 
)

Creates a Pool instance.

Parameters
baseObjectsThe object that will be instantiated by the pool.
sizeThe maximum number of objects that can be instantiated at the same time.
instantiationPositionThe position where the objects must be instantiated.
instantiationRotationThe rotation that the objects must have when instantiated.
instantiateAllAtCreationIf the pool should instantiate all the objects in the scene right away (true) or if they should be instantiated when they are needed (false, default value).
randomInstantiationSequenceIf false, the objects will be instantiated in the appearing order in the 'baseObjects array. If true, the order of instantiation of the pooled objects is going to be random.
intantiationRandomizationSeedThe seed used to randomly pick the baseObjects in the first instantiation process

Definition at line 111 of file PoolEssentials.cs.

Member Function Documentation

◆ Disable() [1/2]

GameObject UnityEngine.PoolEssentials.Disable ( GameObject  gameObject)

Disables the given gameObject if it belongs to the pool.

Parameters
gameObjectThe GameObject to disable.
Returns
The disabled object if it belong to the pool. Null otherwise.

Definition at line 222 of file PoolEssentials.cs.

Here is the caller graph for this function:

◆ Disable() [2/2]

GameObject UnityEngine.PoolEssentials.Disable ( int  gameObjectIndexInPool)

Disables the gameObject in the given index

Parameters
gameObjectIndexInPoolThe index in the pool of the GameObject to disable.
Returns
The disabled object.

Definition at line 241 of file PoolEssentials.cs.

Here is the call graph for this function:

◆ GetNextBaseObjectToInstantiate()

GameObject UnityEngine.PoolEssentials.GetNextBaseObjectToInstantiate ( bool  register)
private

Returns the next BaseObject to be spawned

Parameters
registerShould the request be registered so the next time it is made, the next element is returned?
Returns

Definition at line 200 of file PoolEssentials.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InstantiateNewAt()

GameObject UnityEngine.PoolEssentials.InstantiateNewAt ( int  index,
Transform  parent = null 
)
private

Instantiates an object for the pool.

Be aware: it will only instantiate the new GameObject if the pool size is preserved and if there are non existing GameObjects in the indicated index.

>

Parameters
index
parentThe parent that will be set to the activated object.
Returns

Definition at line 176 of file PoolEssentials.cs.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Load()

void UnityEngine.PoolEssentials.Load ( int  quantity,
Transform  parent = null 
)

Loads an objet to be later activated/used.

Parameters
quantityThe amount of GameObjects that are wanted to be load (but not activated yet)
parentThe parent that will be set to the activated object.

Definition at line 157 of file PoolEssentials.cs.

Here is the call graph for this function:

◆ Spawn()

GameObject UnityEngine.PoolEssentials.Spawn ( Vector3  position,
Quaternion  rotation,
Vector3  scale,
Transform  parent = null 
)

Activates an object from the pool.

The activated object will be chosen dynamically looping between all the objects in the pool.

Parameters
positionThe position where the objects must be moved to.
rotationThe rotation that must be set to the object.
scaleThe scale that must be set to the object.
parentThe parent that will be set to the activated object.

Definition at line 124 of file PoolEssentials.cs.

Here is the call graph for this function:

Member Data Documentation

◆ baseObjects

GameObject [] UnityEngine.PoolEssentials.baseObjects = new GameObject[1]

The prefabs of the GameObjects to be spawned for the pool.

Definition at line 19 of file PoolEssentials.cs.

◆ defaultPositionAndRotation

DefaultPositionAndRotation UnityEngine.PoolEssentials.defaultPositionAndRotation = new DefaultPositionAndRotation()
private

The default position and rotation where the objects are first instantiated

Definition at line 47 of file PoolEssentials.cs.

◆ randomEssentialsInstantiation

RandomEssentials UnityEngine.PoolEssentials.randomEssentialsInstantiation = new RandomEssentials()
private

The randomness generator object used to choose the next base object to instantiate.

Definition at line 43 of file PoolEssentials.cs.

◆ randomInstantiationSequence

bool UnityEngine.PoolEssentials.randomInstantiationSequence = false

Should the selection of the next base object to instantiate be random? If false, the selection will be made in order looping through the baseObjects array.

If true, they will only be chosen randomly for the first instantiation, not the further reactivations.

Definition at line 34 of file PoolEssentials.cs.

◆ referencedObjects

List<GameObject> UnityEngine.PoolEssentials.referencedObjects = new List<GameObject>()
private

A reference to the instantiated GameObjects linked to the pool.

Definition at line 14 of file PoolEssentials.cs.

◆ size

int UnityEngine.PoolEssentials.size = 10

The size of the pool. How many referenced objects it han have.

Definition at line 39 of file PoolEssentials.cs.

Property Documentation

◆ activeIndex

int UnityEngine.PoolEssentials.activeIndex
getprivate set

The index of the next GameObject to be activated/spawned.

Definition at line 23 of file PoolEssentials.cs.

◆ nextBaseObjectIndex

int UnityEngine.PoolEssentials.nextBaseObjectIndex
getprivate set

The index of the base object that is going to be instantiated next.

The index is related to the baseObjects array.

Definition at line 28 of file PoolEssentials.cs.


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