UnityEssentials
Small but useful tools and features for Unity
|
Allows GameObjects pooling by reusing pre-instantiated GameObjects More...
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... | |
Allows GameObjects pooling by reusing pre-instantiated GameObjects
Definition at line 9 of file PoolEssentials.cs.
UnityEngine.PoolEssentials.PoolEssentials | ( | ) |
Creates a Pool instance.
Definition at line 52 of file PoolEssentials.cs.
UnityEngine.PoolEssentials.PoolEssentials | ( | GameObject[] | baseObjects, |
int | size, | ||
bool | instantiateAllAtCreation = false , |
||
bool | randomInstantiationSequence = false , |
||
int | intantiationRandomizationSeed = -1 |
||
) |
Creates a Pool instance.
baseObjects | The object that will be instantiated by the pool. |
size | The maximum number of objects that can be instantiated at the same time. |
instantiateAllAtCreation | If 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). |
randomInstantiationSequence | If 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. |
intantiationRandomizationSeed | The seed used to randomly pick the baseObjects in the first instantiation process |
Definition at line 67 of file PoolEssentials.cs.
UnityEngine.PoolEssentials.PoolEssentials | ( | GameObject | baseObject, |
int | size, | ||
bool | instantiateAllAtCreation = false |
||
) |
Creates a Pool instance.
baseObject | The object that will be instantiated by the pool. |
size | The maximum number of objects that can be instantiated at the same time. |
instantiateAllAtCreation | If 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.
UnityEngine.PoolEssentials.PoolEssentials | ( | GameObject[] | baseObjects, |
int | size, | ||
Vector3 | instantiationPosition, | ||
Quaternion | instantiationRotation, | ||
bool | instantiateAllAtCreation = false , |
||
bool | randomInstantiationSequence = false , |
||
int | intantiationRandomizationSeed = -1 |
||
) |
Creates a Pool instance.
baseObjects | The object that will be instantiated by the pool. |
size | The maximum number of objects that can be instantiated at the same time. |
instantiationPosition | The position where the objects must be instantiated. |
instantiationRotation | The rotation that the objects must have when instantiated. |
instantiateAllAtCreation | If 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). |
randomInstantiationSequence | If 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. |
intantiationRandomizationSeed | The seed used to randomly pick the baseObjects in the first instantiation process |
Definition at line 111 of file PoolEssentials.cs.
GameObject UnityEngine.PoolEssentials.Disable | ( | GameObject | gameObject | ) |
Disables the given gameObject if it belongs to the pool.
gameObject | The GameObject to disable. |
Definition at line 222 of file PoolEssentials.cs.
GameObject UnityEngine.PoolEssentials.Disable | ( | int | gameObjectIndexInPool | ) |
Disables the gameObject in the given index
gameObjectIndexInPool | The index in the pool of the GameObject to disable. |
Definition at line 241 of file PoolEssentials.cs.
|
private |
Returns the next BaseObject to be spawned
register | Should the request be registered so the next time it is made, the next element is returned? |
Definition at line 200 of file PoolEssentials.cs.
|
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.
>
index | |
parent | The parent that will be set to the activated object. |
Definition at line 176 of file PoolEssentials.cs.
void UnityEngine.PoolEssentials.Load | ( | int | quantity, |
Transform | parent = null |
||
) |
Loads an objet to be later activated/used.
quantity | The amount of GameObjects that are wanted to be load (but not activated yet) |
parent | The parent that will be set to the activated object. |
Definition at line 157 of file PoolEssentials.cs.
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.
position | The position where the objects must be moved to. |
rotation | The rotation that must be set to the object. |
scale | The scale that must be set to the object. |
parent | The parent that will be set to the activated object. |
Definition at line 124 of file PoolEssentials.cs.
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.
|
private |
The default position and rotation where the objects are first instantiated
Definition at line 47 of file PoolEssentials.cs.
|
private |
The randomness generator object used to choose the next base object to instantiate.
Definition at line 43 of file PoolEssentials.cs.
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.
|
private |
A reference to the instantiated GameObjects linked to the pool.
Definition at line 14 of file PoolEssentials.cs.
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.
|
getprivate set |
The index of the next GameObject to be activated/spawned.
Definition at line 23 of file PoolEssentials.cs.
|
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.