Last active
June 14, 2019 23:06
-
-
Save EudenDev/e39c7ea13d920f7da09eb2cb592fe1b1 to your computer and use it in GitHub Desktop.
Revisions
-
EudenDev revised this gist
Jun 14, 2019 . 1 changed file with 3 additions and 250 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,256 +1,9 @@ # Pooling System Author: Andres Maldonado -- Original Author: Martin "quill18" Based on this code https://gist.github.com/quill18/5a7cfffae68892621267 Give credit to me as well as the original author if you feel so. :) ## Notice Pooling System has been moved to : https://github.com/eudendeew/Pooling-System -
EudenDev revised this gist
May 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Documentation for the pooling system, this includes as of May 2019: * Pooling.cs: Pool\<T>, PoolMember, ScenePools, Category(enum) * [IPoolable.cs (Interface)](#calling-functions-on-pool-spawn--unspawn) * [ParticleSystemPooling.cs](#particle-sytem-pooling) **Lastest Version: [May2019] v3.3.1 -
EudenDev revised this gist
May 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Documentation for the pooling system, this includes as of May 2019: * Pooling.cs: Pool\<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * [ParticleSystemPooling.cs](#particle-sytem-pooling) **Lastest Version: [May2019] v3.3.1 See the Changelog at the end of this document.** -
EudenDev revised this gist
May 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Documentation for the pooling system, this includes as of May 2019: * Pooling.cs: Pool\<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * [ParticleSystemPooling.cs](https://gist.github.com/eudendeew/e39c7ea13d920f7da09eb2cb592fe1b1#particle-sytem-pooling) **Lastest Version: [May2019] v3.3.1 See the Changelog at the end of this document.** -
EudenDev revised this gist
May 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Documentation for the pooling system, this includes as of May 2019: * Pooling.cs: Pool\<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * [ParticleSystemPooling.cs](https://gist.github.com/quill18/5a7cfffae68892621267#ParticleSytemPooling) **Lastest Version: [May2019] v3.3.1 See the Changelog at the end of this document.** -
EudenDev revised this gist
May 17, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ Documentation for the pooling system, this includes as of May 2019: * Pooling.cs: Pool\<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * [ParticleSystemPooling.cs] **Lastest Version: [May2019] v3.3.1 See the Changelog at the end of this document.** -
EudenDev revised this gist
May 17, 2019 . 1 changed file with 9 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Documentation for the pooling system, this includes as of May 2019: * IPoolable.cs (Interface) * ParticleSystemPooling.cs **Lastest Version: [May2019] v3.3.1 See the Changelog at the end of this document.** Author: Andres Maldonado -- Original Author: Martin "quill18" @@ -173,6 +173,11 @@ pm.OnRecycleToPool(); Since they are at the same level, just use: `pooledGmObject.transform.parent;` ## Particle Sytem Pooling This is a handy component to repool a particle system, like VFXs. Add the component to your particle system, read the tooltip on the component if you need help. This component force loop to false and stopAction to callback. ## POSSIBLE ISSUES - Using generic version Pooling.Pool\<T> then trying Pooling.SendToPool() will not work and **will destroy your object**. @@ -182,6 +187,9 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. - An error may occur after destroying a pooled object and trying GetFromPool or PopFromPool. ## CHANGELOG [May2019] v3.3.1 + Particle Pooling Sytem Manually Stop option, and tooltips [May2019] v3.3.0 + Pooling.Pool class has been deleted, use Pooling.Pool\<Transform> instead. + Text fixes -
EudenDev revised this gist
May 2, 2019 . No changes.There are no files selected for viewing
-
EudenDev revised this gist
May 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -183,7 +183,7 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. ## CHANGELOG [May2019] v3.3.0 + Pooling.Pool class has been deleted, use Pooling.Pool\<Transform> instead. + Text fixes [may2019] v3.2.0 -
EudenDev revised this gist
May 2, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,7 @@ See the Changelog at the end of this document.** Author: Andres Maldonado -- Original Author: Martin "quill18" Based on this code https://gist.github.com/quill18/5a7cfffae68892621267 Give credit to me as well as the original author if you feel so. :) ## BASIC USAGE -
EudenDev revised this gist
May 2, 2019 . 1 changed file with 12 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,16 @@ # Pooling System Documentation Documentation for the pooling system, this includes as of May 2019: * Pooling.cs: Pool\<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * ParticleSystemPooling.cs **Lastest Version: [May2019] v3.3.0 See the Changelog at the end of this document.** Author: Andres Maldonado -- Original Author: Martin "quill18" Based on this code https://gist.github.com/quill18/5a7cfffae68892621267 Give credit to me as well as the original author if you feel so. :) ## BASIC USAGE @@ -146,12 +146,14 @@ myOwnPool.PushToPoolLastest(true); ```csharp // Get List of active objects. List<T> Actives { private set; get; } // Push to pool all active objects. myScriptPool.PushToPoolAll(true); public void PushToPoolAll(bool useCallback) // Pushes back to pool the most recent object. public void PushToPoolLastest(bool useCallback) ``` ### PoolMember component methods @@ -179,6 +181,10 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. - An error may occur after destroying a pooled object and trying GetFromPool or PopFromPool. ## CHANGELOG [May2019] v3.3.0 + Pooling.Pool class has been deleted, use Pooling.Pool<Transform> + Text fixes [may2019] v3.2.0 + Pooling.Pool now uses Component instead of MonoBehaviour -
EudenDev revised this gist
May 2, 2019 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Documentation for the pooling system, this includes as of April 2019: * IPoolable.cs (Interface) * ParticleSystemPooling.cs **Lastest Version: [may2019] v3.2.0 See the Changelog at the end of this document.** Author: Andres Maldonado -- Original Author: Martin "quill18" @@ -179,6 +179,9 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. - An error may occur after destroying a pooled object and trying GetFromPool or PopFromPool. ## CHANGELOG [may2019] v3.2.0 + Pooling.Pool now uses Component instead of MonoBehaviour [apr2019] v3.1.0 + Pooling.Pool generic version. + Some nullchecks -
EudenDev revised this gist
Apr 26, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -171,7 +171,7 @@ Since they are at the same level, just use: `pooledGmObject.transform.parent;` ## POSSIBLE ISSUES - Using generic version Pooling.Pool\<T> then trying Pooling.SendToPool() will not work and **will destroy your object**. *(Not known but it might happen)* - When changing a scene, the objects are destroyed and their reference too, for now -
EudenDev revised this gist
Apr 26, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -144,7 +144,7 @@ myOwnPool.PushToPoolLastest(true); ### Generic Version Extra Methods ```csharp // Get List of active objects. myScriptPool.Actives; List<T> Actives { private set; get; } -
EudenDev revised this gist
Apr 26, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Pooling System Documentation Documentation for the pooling system, this includes as of April 2019: * Pooling.cs: Pool, Pool\<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * ParticleSystemPooling.cs -
EudenDev revised this gist
Apr 26, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Pooling System Documentation Documentation for the pooling system, this includes as of April 2019: * Pooling.cs: Pool, Pool/<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * ParticleSystemPooling.cs -
EudenDev revised this gist
Apr 26, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # Pooling System Documentation Documentation for the pooling system, this includes as of April 2019: * Pooling.cs: Pool, Pool<T>, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * ParticleSystemPooling.cs -
EudenDev revised this gist
Apr 26, 2019 . 1 changed file with 27 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Documentation for the pooling system, this includes as of April 2019: * IPoolable.cs (Interface) * ParticleSystemPooling.cs **Lastest Version: [apr2019] v3.1.0 See the Changelog at the end of this document.** Author: Andres Maldonado -- Original Author: Martin "quill18" @@ -90,12 +90,15 @@ Intead of accumulating in the main dictionnary inside Pooling. public class ExampleClass : MonoBehaviour { public GameObject prefab; private Pooling.Pool myOwnPool; private Pooling.Pool<MyScript> objectPool; void Start() { // - Basic Pool myOwnPool = new Pooling.Pool(prefab) // OR - Preloaded Pool myOwnPool = new Pooling.Pool(prefab, 10, true) // - Generic version objectPool = new Pooling.Pool<MyScript>(prefab.GetComponent<MyScript>()); } public void SpawnVFX(Vector3 position, Quaternion rotation) { @@ -110,6 +113,9 @@ myOwnPool = new Pooling.Pool(prefab); // Preloaded, spawns the objects already deactivated. myOwnPool = new Pooling.Pool(prefab, 10, true); // Generic version. myScriptPool = new Pooling.Pool<MyScript>(prefab.GetComponent<MyScript>()); ``` ### Pooling.Pool Methods @@ -136,6 +142,18 @@ myOwnPool.PushToPoolLastest(); myOwnPool.PushToPoolLastest(true); ``` ### Generic Version Extra Methods ``` // Get List of active objects. myScriptPool.Actives; List<T> Actives { private set; get; } // Push to pool all active objects. myScriptPool.PushToPoolAll(true); public void PushToPoolAll(bool useCallback = false) ``` ### PoolMember component methods ```csharp // Use this if you add on runtime, a component that uses IPoolable. @@ -153,13 +171,19 @@ Since they are at the same level, just use: `pooledGmObject.transform.parent;` ## POSSIBLE ISSUES - Using Pooling.Pool<T> then trying Pooling.SendToPool() will not work and **will destroy your object**. *(Not known but it might happen)* - When changing a scene, the objects are destroyed and their reference too, for now there is no way to dealloacate a Pool. Except with manually managed Pools. - An error may occur after destroying a pooled object and trying GetFromPool or PopFromPool. ## CHANGELOG [apr2019] v3.1.0 + Pooling.Pool generic version. + Some nullchecks + Documentation only available here from now [apr2019] v3.0.2 + SendBackToPool refactored to ParticleSystemPooling. + Added Summaries @@ -186,11 +210,7 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. - PoolMemberhas been simplified v2.5 [fev2019] // ANDRES - Removed ScenePools from project + Integrated Categories + Addded documentation + Clean Up -
EudenDev revised this gist
Apr 23, 2019 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ Use: `Pooling.SendToPool(yourGameObject);` use Pooling.Preload() on Start. * Destroying an object with delay is not yet supported. e.g. Destroy(yourGO, 3f); ## ADVANCED USAGE ### CALLING FUNCTIONS ON POOL SPAWN / UNSPAWN This could be used for resetting an enemy health, or leaving something behind when an enemy disappears. @@ -104,15 +104,15 @@ public class ExampleClass : MonoBehaviour { } ``` ### Constructors ```csharp // Basic - doesn't spawn anything. myOwnPool = new Pooling.Pool(prefab); // Preloaded, spawns the objects already deactivated. myOwnPool = new Pooling.Pool(prefab, 10, true); ``` ### Pooling.Pool Methods ```csharp // Simple Spawn myOwnPool.PopFromPool(position, rotation); @@ -136,7 +136,7 @@ myOwnPool.PushToPoolLastest(); myOwnPool.PushToPoolLastest(true); ``` ### PoolMember component methods ```csharp // Use this if you add on runtime, a component that uses IPoolable. // The list of receivers needs to be manually updated. @@ -153,7 +153,7 @@ Since they are at the same level, just use: `pooledGmObject.transform.parent;` ## POSSIBLE ISSUES *(Not known but it might happen)* - When changing a scene, the objects are destroyed and their reference too, for now there is no way to dealloacate a Pool. Except with manually managed Pools. - An error may occur after destroying a pooled object and trying GetFromPool or PopFromPool. -
EudenDev revised this gist
Apr 23, 2019 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -186,8 +186,10 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. - PoolMemberhas been simplified v2.5 [fev2019] // ANDRES **ScenePools.cs** - Removed from project **Pooling.cs** + Integrated Categories + Addded documentation -
EudenDev revised this gist
Apr 23, 2019 . 1 changed file with 18 additions and 22 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -113,32 +113,28 @@ Preloaded, spawns the objects already deactivated. `myOwnPool = new Pooling.Pool(prefab, 10, true)` ### Methods ```csharp // Simple Spawn myOwnPool.PopFromPool(position, rotation); // Spawn and call IPoolable.OnPoolSpawn() myOwnPool.PopFromPool(position, rotation, true); // Stock reference GameObject gmObj = myOwnPool.PopFromPool(position, rotation, true); // Send back myOwnPool.PushToPool(gmObj); // Send back and call IPoolable.OnPoolUnSpawn() myOwnPool.PushToPool(gmObj, true); // Send back last spawned myOwnPool.PushToPoolLastest(); // It can also call IPoolable.OnPoolUnSpawn() myOwnPool.PushToPoolLastest(true); ``` ### Pool Member methods ```csharp @@ -190,9 +186,9 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. - PoolMemberhas been simplified v2.5 [fev2019] // ANDRES **ScenePools.cs** - Removed from project **Pooling.cs** + Integrated Categories + Addded documentation + Clean Up -
EudenDev revised this gist
Apr 23, 2019 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -54,16 +54,21 @@ not on any child object.** Could be used in the beginning of the game to reduce the cost of creating a new instance of your prefab. Use: ```csharp Pooling.Preload(prefabReference, 8); ``` * Returns an array of gameObjects. * Cannot use Pooling Categories. * Pools are always dynamic, they will resize if a new instance is needed. ### POOL CATEGORIES Objects that are used between levels can be organized inside categories, all marked as DontDestroyOnLoad. To do so use: ```csharp Pooling.GetFromPool(prefab, pos, rot, Pooling.Category.Projectiles); ``` * Current existing categories are: Projectiles, Enemies, VisualEffects. * Again, objects spawned with this method are marked as **DontDestroyOnLoad**. @@ -160,13 +165,13 @@ there is no way to dealloacate a Pool. Except with manually managed Pools. ## CHANGELOG [apr2019] v3.0.2 + SendBackToPool refactored to ParticleSystemPooling. + Added Summaries + Null prefab reference error + Text fixes [apr2019] v3.0.0 + Manually managed pools + Documentation added + More summaries and functions -
EudenDev revised this gist
Apr 23, 2019 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,11 @@ # Pooling System Documentation Documentation for the pooling system, this includes as of April 2019: * Pooling.cs: Pool, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * ParticleSystemPooling.cs **Lastest Version: [apr2019] v3.0.2 See the Changelog at the end of this document.** Author: Andres Maldonado -- Original Author: Martin "quill18" @@ -23,7 +22,7 @@ Instead of: `Destroy(yourGameObject);` Use: `Pooling.SendToPool(yourGameObject);` * Trying SendToPool() on not pooled objects will call Destroy() instead, a message on the console should confirm this. * The pool will resize if a new instance is needed. To reduce the impact use Pooling.Preload() on Start. -
EudenDev revised this gist
Apr 19, 2019 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,11 @@ Don't forget to give credit to me as well as the original author. ## BASIC USAGE Instead of: `Instantiate(yourPrefab, position, rotation);` Use: `Pooling.GetFromPool(yourPrefab, position, rotation);` Instead of: `Destroy(yourGameObject);` Use: `Pooling.SendToPool(yourGameObject);` * Trying SendToPool() on not pooled objects will call Destroy instead, a message -
EudenDev revised this gist
Apr 19, 2019 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,11 @@ Don't forget to give credit to me as well as the original author. ## BASIC USAGE Instead of: `Instantiate(yourPrefab, position, rotation);` Use: `Pooling.GetFromPool(yourPrefab, position, rotation);` Instead of: `Destroy(yourGameObject);` Use: `Pooling.SendToPool(yourGameObject);` * Trying SendToPool() on not pooled objects will call Destroy instead, a message on the console should confirm this. -
EudenDev revised this gist
Apr 19, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
EudenDev revised this gist
Apr 19, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ Test -
EudenDev created this gist
Apr 19, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,214 @@ # Pooling System Documentation Documentation for the pooling system, this includes as of April 2019: * Pooling.cs: Pool, PoolMember, ScenePools, Category(enum) * IPoolable.cs (Interface) * ParticleSystemPooling.cs **Version: [apr2019] v3.0.2 See the Changelog at the end of this document.** Author: Andres Maldonado -- Original Author: Martin "quill18" Based on this code https://gist.github.com/quill18/5a7cfffae68892621267 Don't forget to give credit to me as well as the original author. ## BASIC USAGE Instead of: Instantiate(yourPrefab, position, rotation); Use: Pooling.GetFromPool(yourPrefab, position, rotation); Instead of: Destroy(yourGameObject); Use: Pooling.SendToPool(yourGameObject); * Trying SendToPool() on not pooled objects will call Destroy instead, a message on the console should confirm this. * The pool will resize if a new instance is needed. To reduce the impact use Pooling.Preload() on Start. * Destroying an object with delay is not yet supported. e.g. Destroy(yourGO, 3f); ## ADVANCED ### CALLING FUNCTIONS ON POOL SPAWN / UNSPAWN This could be used for resetting an enemy health, or leaving something behind when an enemy disappears. In your script use the interface IPoolable, implement it like this: ```csharp public class Enemy : MonoBehavior, IPoolable { <...your code...> public void OnPoolSpawn() { // - Code to be run after this object is spawned and enabled. } public void OnPoolUnSpawn() { // - Code to be run before this object is unspawned and disabled. } } ``` **Scripts that use IPoolable should be on the root of the prefab, not on any child object.** ### PRELOAD OBJECTS Could be used in the beginning of the game to reduce the cost of creating a new instance of your prefab. Use: Pooling.Preload(prefabReference, 8); * Returns an array of gameObjects. * Cannot use Pooling Categories. * Pools are always dynamic, they will resize if a new instance is needed. ### POOL CATEGORIES Objects that are used between levels can be organized inside categories, all marked as DontDestroyOnLoad. To do so use: Pooling.GetFromPool(prefab, pos, rot, Pooling.Category.Projectiles); * Current existing categories are: Projectiles, Enemies, VisualEffects. * Again, objects spawned with this method are marked as **DontDestroyOnLoad**. ### KNOW IF A GAME OBJECT COMES FROM A POOL You can use GetComponent<PoolMember>() to check if the object comes from the pooling system. Inside you can have access to some advanced methods. * There are some exposed functions that is better not to touch them because they are used for calling the interfaces and reference its parent pool. ## SUPER ADVANCED USAGE ### MANUALLY MANAGED POOLS Another way to create Pools is with Pooling.Pool: One big advantage is that unreferenced pools will be collected by the GC. Intead of accumulating in the main dictionnary inside Pooling. ```csharp public class ExampleClass : MonoBehaviour { public GameObject prefab; private Pooling.Pool myOwnPool; void Start() { // - Basic Pool myOwnPool = new Pooling.Pool(prefab) // OR - Preloaded Pool myOwnPool = new Pooling.Pool(prefab, 10, true) } public void SpawnVFX(Vector3 position, Quaternion rotation) { myOwnPool.PopFromPool(position, rotation, true); } } ``` ### Constructors Basic - doesn't spawn anything. `myOwnPool = new Pooling.Pool(prefab)` Preloaded, spawns the objects already deactivated. `myOwnPool = new Pooling.Pool(prefab, 10, true)` ### Methods * Simple Spawn `myOwnPool.PopFromPool(position, rotation);` * Spawn and call IPoolable.OnPoolSpawn() `myOwnPool.PopFromPool(position, rotation, true);` * Stock reference `GameObject gmObj = myOwnPool.PopFromPool(position, rotation, true);` * Send back `myOwnPool.PushToPool(gmObj);` * Send back and call IPoolable.OnPoolUnSpawn() `myOwnPool.PushToPool(gmObj, true);` * Send back last spawned `myOwnPool.PushToPoolLastest();` * It can also call IPoolable.OnPoolUnSpawn() `myOwnPool.PushToPoolLastest(true);` ### Pool Member methods ```csharp // Use this if you add on runtime, a component that uses IPoolable. // The list of receivers needs to be manually updated. Pooling.PoolMember pm = GetComponent<Pooling.PoolMember>(); pm.SearchInterfaces(); // It updates interfaces to be called. // This forces all the calls of IPoolable.OnPoolSpawn and IPoolable.OnPoolUnSpawn pm.OnDeployFromPool(); pm.OnRecycleToPool(); ``` ### Get Category transform Since they are at the same level, just use: `pooledGmObject.transform.parent;` ## POSSIBLE ISSUES (Not known but it might happen) - When changing a scene, the objects are destroyed and their reference too, for now there is no way to dealloacate a Pool. Except with manually managed Pools. - An error may occur after destroying a pooled object and trying GetFromPool or PopFromPool. ## CHANGELOG [apr2019] v3.0.2 ++ SendBackToPool refactored to ParticleSystemPooling. + Added Summaries + Null prefab reference error + Text fixes [apr2019] v3.0.0 ++ Manually managed pools + Documentation added + More summaries and functions [apr2019] v2.6.2 + Send Back to Pool nullcheck + Text Fixes + PoolMember summaries and SearchInterfaces method [mar2019] v2.6.0 // ANDRES + Pooling.Preload: Returns an array of gameObjects. + Documentation text fixes [fev2019] v2.5.5 // ANDRES + More Documentation - IPoolable has been simplified - PoolMemberhas been simplified v2.5 [fev2019] // ANDRES :: ScenePools.cs - Removed from project :: Pooling.cs + Integrated Categories + Addded documentation + Clean Up v2.1 [jan2019] // ANDRES + Removed debug logs and minor fixes v2.0 [dec2018] // ANDRES + ScenePools.cs, organizes spawn object into transforms in the scene + Added Pools Presets + Multiple IPoolable compatibility v1.6 [aug2018] // ANDRES + Mayor Fixes to all the system + Commentatries and summaries v1.5 [aug2018] // ANDRES + IPoolable corrections + Particle System Pooling, SendBackToPool.cs v1.2 [jul2018] // ANDRES + IPoolable interface compatibility v1 [jun2018] // Andres - Martin "quill18" + Simple Pooling, Pool Member