1 using System.Collections.Generic;
18 [Tooltip(
"The prefabs of the GameObjects to be spawned for the pool.")]
33 [Tooltip(
"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.")]
38 [Tooltip(
"The size of the pool. How many referenced objects it han have.")]
75 if (intantiationRandomizationSeed != -1)
76 this.randomEssentialsInstantiation =
new RandomEssentials(intantiationRandomizationSeed);
78 if (instantiateAllAtCreation)
79 for (
int i = 0; i <
size; i++)
91 this.baseObjects =
new GameObject[] {baseObject};
96 if (instantiateAllAtCreation)
97 for (
int i = 0; i <
size; i++)
111 public PoolEssentials(GameObject[]
baseObjects,
int size, Vector3 instantiationPosition, Quaternion instantiationRotation,
bool instantiateAllAtCreation =
false,
bool randomInstantiationSequence =
false,
int intantiationRandomizationSeed = -1) : this(
baseObjects,
size, instantiateAllAtCreation,
randomInstantiationSequence, intantiationRandomizationSeed)
124 public GameObject
Spawn(Vector3 position, Quaternion rotation, Vector3 scale, Transform parent =
null)
133 "An error occured trying to spawn the GameObject using the class Pool\nBe sure that your pools are properly configured.");
157 public void Load(
int quantity, Transform parent =
null)
160 for (
int i = 0; i <
size; i++)
164 if (remainingQuantity <= 0)
182 Debug.LogWarning($
"Trying to instantiate an object in the pool '{this}' but the expected index of the object should be {referencedObjects.Count} and it is {index}.");
186 if(nextToInstantiate ==
null)
222 public GameObject
Disable(GameObject gameObject)
226 gameObject.SetActive(
false);
231 Debug.LogWarning(
"Trying to disable an object ("+gameObject.name+
") from a pool that doesn't belong to.");
241 public GameObject
Disable(
int gameObjectIndexInPool)
249 [System.Serializable]
Allows GameObjects pooling by reusing pre-instantiated GameObjects
GameObject Disable(int gameObjectIndexInPool)
Disables the gameObject in the given index
GameObject InstantiateNewAt(int index, Transform parent=null)
Instantiates an object for the pool.
GameObject Spawn(Vector3 position, Quaternion rotation, Vector3 scale, Transform parent=null)
Activates an object from the pool.
bool randomInstantiationSequence
Should the selection of the next base object to instantiate be random? If false, the selection will b...
GameObject Disable(GameObject gameObject)
Disables the given gameObject if it belongs to the pool.
GameObject[] baseObjects
The prefabs of the GameObjects to be spawned for the pool.
DefaultPositionAndRotation defaultPositionAndRotation
The default position and rotation where the objects are first instantiated
GameObject GetNextBaseObjectToInstantiate(bool register)
Returns the next BaseObject to be spawned
PoolEssentials(GameObject[] baseObjects, int size, bool instantiateAllAtCreation=false, bool randomInstantiationSequence=false, int intantiationRandomizationSeed=-1)
Creates a Pool instance.
PoolEssentials(GameObject[] baseObjects, int size, Vector3 instantiationPosition, Quaternion instantiationRotation, bool instantiateAllAtCreation=false, bool randomInstantiationSequence=false, int intantiationRandomizationSeed=-1)
Creates a Pool instance.
PoolEssentials(GameObject baseObject, int size, bool instantiateAllAtCreation=false)
Creates a Pool instance.
int activeIndex
The index of the next GameObject to be activated/spawned.
List< GameObject > referencedObjects
A reference to the instantiated GameObjects linked to the pool.
RandomEssentials randomEssentialsInstantiation
The randomness generator object used to choose the next base object to instantiate.
int size
The size of the pool. How many referenced objects it han have.
int nextBaseObjectIndex
The index of the base object that is going to be instantiated next.
PoolEssentials()
Creates a Pool instance.
void Load(int quantity, Transform parent=null)
Loads an objet to be later activated/used.
Class to handle the default position and rotation where the objects are first instantiated
DefaultPositionAndRotation(Vector3 instantiationPosition, Quaternion instantiationRotation)
DefaultPositionAndRotation()
Quaternion instantiationRotation
The default rotation of the new instantiated objects
Vector3 instantiationPosition
The default position where the objects will be instantiated
An easier to use and a feature-rich class to generate pseudo-random results.