TIGERFORGE
Easy Pooling PLUS
Introduction
[SP]Easy Pooling PLUS[S] is an easy and practical way to integrate a pooling system in your game. It has been designed to be very easy and fast to use, but complete and powerful as well.

[t[WHAT POOLING IS]] The pooling is a development technique for improving performance and memory use when you need to spawn and reuse more copies of the same object. Creating and then destroying the same objects (for instance, dozens of bullets fired by a gun) is memory and efficiency consuming. The idea behind the pooling system is to generate a collection of all copies of the same object, keeping track of which is in use and which is unused. When the game will requests that object, the pooling system will get an unused object from the collection. If it's not found, the pooling system will create a new object, keeping track of it.

[t[HOW IT WORKS]] [SP]Easy Pooling PLUS[S] engine resides in a Unity ScriptableObject. The first thing to do is to create a new Pooler, right-clicking on the Project panel and navigating through TigerForge > Easy Pooling Plus menu.
A Pooler is an interface that allows defining the list of objects you can spawn. It supports Prefabs and Audio Clips. For each item, you can define specific options.
POOLER INTERFACE
When you click the TigerForge > Easy Pooling Plus > New Pooler menu, a new Pooler component is created in your Project. You can create all the Poolers you need without limitations. Its interface allows selecting the object that can be managed by [SP]Easy Pooling PLUS[S]. The system can manage Prefabs (3D objects, Particles, etc.) and Audio Clips. Prefabs and Audio Clips are defined into separated lists with specific options.



[p[Disable Warnings]] During the use of [SP]Easy Pooling PLUS[S], the engine checks that everything is correctly configured. If something is missed, various warning messages can appear in the Unity Console. Usually, they are warnings about misconfigurations and they don't block the engine execution. However, it's possible to suppress those messages just checking this field.

[p[Prefabs and Audio Clips]] This is the list of Prefabs and Audio Clips that [SP]Easy Pooling PLUS[S] can manage. It shouldn't be a generic list of all the game objects you want to pool, but it should be just the list of objects another object needs to spawn. For instance, the list of the different bullets a gun can fire with their sound effects.
Because Prefabs and Audio Clips are two different kinds of game objects, they have specific options and features.

[p[Prefabs list]] This is the list of Prefabs that can be spawned and managed by the pooling system. For each Prefab you can specify the following properties:
ID Each item must have an ID. The ID must be a unique string. Even if you're free to type any kind of string, it's recommended to type simple strings, as if they were variable names (letters, numbers and the underscore symbol for space). This ID will be used by the [SP]Easy Pooling PLUS[S] methods to have a reference to this Prefab.
Prefab This is the link to your Project Prefab. [SP]Easy Pooling PLUS[S] can spawn any kind of object that can be turned into a Prefab.
Create On Start It's the number of Prefabs to instantiate when the game starts. In this case, [SP]Easy Pooling PLUS[S] immediately creates the specified quantity of Prefabs and stores them in the Pool collection, ready to be used by the pooling system. This feature improves the game efficiency and performances if you already know how many Prefabs it's going to use.
Destroy Type [SP]Easy Pooling PLUS[S] comes with two built-in ways to understand when a Pool Prefab can be reused:
Set Inactive (default): this is a common approach in the pooling system. In this case, when a Prefab becomes unused (for instance, the bullet hits the enemy), it gets disabled by setActive(false). With the 'Set Inactive' option, the pooling system will look for disabled objects.
Set Position: this technique simply moves an unused object outside the camera view, without modifying its status. In this case, you must define a value for Z coordinate so as to place the unused objects in a distant point, far from the camera.
Destroy Position It's the value of the Z coordinate of the unused (destroyed) Prefab when the 'Set Position' technique is selected.

[p[Audio Clips list]] This is the list of Audio Clips that can be spawned and managed by the pooling system. For each Audio Clip you can specify the following properties:
ID Each item must have an ID. The ID must be a unique string. Even if you're free to type any kind of string, it's recommended to type simple strings, as if they were variable names (letters, numbers and the underscore symbol for space). This ID will be used by the [SP]Easy Pooling PLUS[S] methods to have a reference to this Audio Clip.
Audio Clip This is the link to your Project Audio Clip. [SP]Easy Pooling PLUS[S] will spawn and play this Audio Clip when requested.
Volume It's the default volume when an Audio Clip is played.
Delay By default, an Audio Clip is played immediately. If you need to delay its execution, you can define the number of delay seconds here.
Create On Start It's the number of Audio Clips to instantiate when the game starts. In this case, [SP]Easy Pooling PLUS[S] immediately creates the specified quantity of Audio Clips (without playing them) and stores them in the Pool collection, ready to be used by the pooling system. This feature improves the game efficiency and performances if you already know how many Audio Clips it's going to use.
USING THE POOLING SYSTEM
The use of the pooling system requires C# coding, so you have total control on where and when the system has to work. Basically, a single Pooler is a collection of objects (Prefabs and Audio Clips) used by another object (for instance, the collection of bullets and sounds used by a gun). This means you have to start linking the Pooler to the object that needs to spawn objects with the pooling technique.

[t[LINKING TO A POOLER]] The Pooler is a Unity ScriptableObject, so you have just to define an EasyPoolingPlus public variable in your object MonoBehaviour class.

Example
using UnityEngine; // Remember to import TigerForge namespace. using TigerForge; public class Gun : MonoBehaviour { -// Create a public variable of EasyPoolingPlus class so as to have a link for a Pooler. -public EasyPoolingPlus bulletsPool; -// Default Start() Unity function -void Start() { -} }
[t[START THE POOLING SYSTEM]] The pooling system engine of [SP]Easy Pooling PLUS[S] must be started before using it. In this way, you have control of where and when the pooling system has to start working. To start the Pooler engine you have just to call the Start() Pooler method:

variable_name.Start()


Example
using UnityEngine; using TigerForge; public class Gun : MonoBehaviour { -public EasyPoolingPlus bulletsPool; -void Start() { --// The pooling system for the bulletsPool Pooler will start when the game starts. --bulletsPool.XXStarXX(); -} }
[t[SPAWNING A PREFAB]] Normally, when you need to spawn a Prefab, you use Unity Instantiate() method. Now, the instantiation of Prefabs is the job of the Pooler. It will search for an existing instance and, if it's found, it will return it, in order to reuse that object. If an instance doesn't exist or there aren't reusable instances, the Pooler will create a new one. The new one will be included in the pooling system logic.
To get a Prefab you have just to call the GetPrefab() Pooler method, specifyng the ID of the Prefab. Keep in mind that the released Prefab is activated and working:

variable_name.GetPrefab(ID, position)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {ID!string!The unique ID that identifies the Prefab.} {position!Vector3 (optional)!The position where the Prefab has to be placed.} {{Returned value{}Description}} {GameObject!The Prefab instantiated or reused by the Pooler.}
Example
using UnityEngine; using TigerForge; public class Gun : MonoBehaviour { -public EasyPoolingPlus bulletsPool; -void Start() { --bulletsPool.XXStarXX(); -} -// Default Update() Unity function. -void Update() { --if (Input.GetKeyUp(KeyCode.A)) --{ ---// When the user press [A] key, the "BULLET_SPHERE" Prefab is released by the Pooler (in the same Gun position; it's optional). ---// If it's a new instantiated Prefab or a reused Prefab is a decision of the Pooler. ---GameObject bullet = bulletsPool.GetPrefab("BULLET_SPHERE", gameObject.transform.position); ---// 'bullet' variable contains the released GameObject. From here, you can continue working with this object as usual. ---// ... --} -} }
[t[SPAWNING AN AUDIO CLIP]] In general, the spawning of Audio Clips works with the same logic of Prefabs spawning. The difference is that the Pooler looks for not playing Audio Clips. If a sound is not playing, the Pooler plays it. If there aren't Audio Clips or all the Audio Clips are playing, the Pooler will create a new one. The new one will be included in the pooling system logic.
To get an Audio Clip you have just to call the GetAudioClip() Pooler method, specifyng the ID of the Audio Clip. The Pooler will play it, according with the Pooler settings, and will release a Unity AudioSource item:

variable_name.GetAudioClip(ID, position, play)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {ID!string!The unique ID that identifies the Prefab.} {position!Vector3 (optional)!The position where the Prefab has to be placed.} {play!Bool (optional)!It determines if the Audio Clip has to be played or it has to be released without playing it. It's true by default. You can set it to false if you need to have total control of the released AudioSource.} {{Returned value{}Description}} {AudioSource!The AudioSource instantiated or reused by the Pooler.}
Example
using UnityEngine; using TigerForge; public class Gun : MonoBehaviour { -public EasyPoolingPlus bulletsPool; -void Start() { --bulletsPool.XXStarXX(); -} -void Update() { --if (Input.GetKeyUp(KeyCode.A)) --{ ---GameObject bullet = bulletsPool.GetPrefab("BULLET_SPHERE", gameObject.transform.position); ---// The "SHOOT" Audio Clip is played as the Gun fires a bullet. ---AudioSource shoot = bulletsPool.GetAudioClip("SHOOT", gameObject.transform.position); --} -} }
[t[PREFAB DESTROYING]] While an Audio Clip is intended unused when it's simply not playing, a Prefab can be considered unused in two different situations, as selected by the developer in the 'Destroy Type' parameter in the Pooler settings.
Both situations can be manually managed by the developer, using SetActive(false) method for the 'Set Inactive' feature or transform.position with the specified Z coordinate value for the "Set Position" feature.
However, [SP]Easy Pooling PLUS[S] comes with an EasyPoolingPlusSystem class that makes the Prefab destroying procedure pretty easier and according to the Pooler settings. To destroy a Prefab you have just to call the Destroy() method of the EasyPoolingPlusSystem class:

EasyPoolingPlusSystem.Destroy(gameObject)

Example
using UnityEngine; using TigerForge; public class Bullet : MonoBehaviour { // It's supposed that this DestroyMe() function is called when this Bullet has to me destroyed for the provided reasons. -void DestroyMe() { --// Just pass gameObject to the Destoy() method. --EasyPoolingPlusSystem.XXDesXX(gameObject); -} }
MANAGEMENT METHODS
[SP]Easy Pooling PLUS[S] comes with some methods to get information or perform specific actions.

[t[ClearPrefabsPool]] Remove all the Prefabs from the Pool.

variable_name.ClearPrefabsPool(destroy, ID)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {destroy!Bool (optional)!If set to true, it phisically destroy the Prefabs.} {ID!String (optional)!If specified, it looks for the Prefabs with this ID.}

[t[ClearAudioClipsPool]] Remove all the Audio Clips from the Pool.

variable_name.ClearAudioClipsPool(destroy, ID)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {destroy!Bool (optional)!If set to true, it phisically destroy the Audio Clips.} {ID!String (optional)!If specified, it looks for the Audio Clips with this ID.}

[t[ClearAllPools]] Remove all the Prefabs and Audio Clips from the Pool.

variable_name.ClearAllPools(destroy)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {destroy!Bool (optional)!If set to true, it phisically destroy Prefabs and Audio Clips.}

[t[Stop]] Stop the execution of the Pooler, removing all the Prefabs and Audio Clips from the Pool and destroying them. Note that it's the equivalent of calling ClearAllPools(true) method. The Stop() method is offered in connection with the Start() method.

variable_name.Stop()
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.}

[t[Pause]] Suspend (isPaused set to true) or restart (isPaused set to false) the pooling system execution. When the system is paused, it stops spawning and reusing Prefabs and AudioClips.
IMPORTANT: Pay attention that, when the system is paused, GetPrefab() and GetAudioClip() methods continue working, but they release a null object.

variable_name.Pause(isPaused)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {isPaused!Bool!Suspend (isPaused set to true) or restart (isPaused set to false) the pooling system execution.}

[t[GetPrefabsPoolSize]] Return the number of Prefabs stored in the Pool.

variable_name.GetPrefabsPoolSize(ID)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {ID!String (optional)!If specified, it looks for the items with this ID.} {{Returned value{}Description}} {Int!The number of items into the Pool.}

[t[GetAudioClipsPoolSize]] Return the number of Audio Clips stored in the Pool.

variable_name.GetAudioClipsPoolSize(ID)
{{Parameter{}Type{}Description}} {variable_name!!The name of the EasyPoolingPlus instance.} {ID!String (optional)!If specified, it looks for the items with this ID.} {{Returned value{}Description}} {Int!The number of items into the Pool.}