|
1 |
| -# Object pooling within unity |
2 |
| - |
3 |
| - |
| 1 | +# Runtime-extendible Object-pooler within unity |
4 | 2 |
|
5 | 3 | You may have made games in the past that created and destroyed a lot of items (such as bullets or enemies).
|
6 | 4 | What you may not have known is that the act of instantiating and destroying are inefficient and can slow your projects down.
|
7 | 5 | This is where Object-pooling comes in . This project contains fully finished example of a object-pooler .
|
8 | 6 |
|
9 | 7 | This pool creates objects that you defined on start and creates additionally if more spawn request comes to the pool than pools capacity and manages newly added pool objects too ! .
|
10 | 8 |
|
11 |
| -Add this pooler to your project and start using directly ! |
| 9 | + |
| 10 | +## Import |
| 11 | + |
| 12 | +1. Go to [release](https://github.com/ertanturan/UnityObjectPooling/releases) page. |
| 13 | +2. Download the lates release of the package. |
| 14 | +3. Import it to your unity project. |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +1. Head to your hierarchy >> Right Click >> Create Empty |
| 19 | +2. Add Component >> Object Pooler >> Set size that you wish to add to your project. |
| 20 | +3. Create Script which inherits from PooledObject Class |
| 21 | + |
| 22 | +`` public Class ExampleClass : PooledObject`` |
| 23 | + |
| 24 | +4. Add a type to 'enum PooledObjectType' (Can be found under Assets/Scripts/ObjectPool/PoolderObjectType.cs) |
| 25 | +5. Retrun to the game object you created on hierarchy drag and drop your prefab to Prefab property on objectpooler's pool . Set the tag you wrote on step 4. set size (How many object you want to create on beginning). |
| 26 | + |
| 27 | + |
| 28 | +### To Spawn and Despawn |
| 29 | + |
| 30 | +`` ObjectPooler.Instance.SpawnFromPool(PooledObjectType.YourTypeComesHere , transform.position, Random.rotation); `` |
| 31 | + |
| 32 | +Attention ! : Despawn should be called from the pooled object . |
| 33 | +`` ObjectPooler.Instance.Despawn(Type,gameObject); `` |
| 34 | + |
| 35 | +## Demo Project |
| 36 | + |
| 37 | +Demo project can be found under 'Assets/Scenes' folder named ' Main ' |
| 38 | + |
| 39 | +## Contributing |
| 40 | +Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. |
| 41 | + |
| 42 | +Please make sure to update tests as appropriate. |
| 43 | + |
| 44 | + |
| 45 | +# ENJOY ! |
0 commit comments