Object Pool
Simple object pool package
com.maxif.objectpool 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/maxi-f-objectpool.git README Markdown
Copy this to your project's README.md
## Installation
Add **Object Pool** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/maxi-f-objectpool.git
```
[](https://www.pkglnk.dev/pkg/maxi-f-objectpool)README
Simple Object Pool
This package aims to add a simple object pool interface. It uses a Factory interface that is used in the Object Pool to create more objects if needed (This means that this object pool can be expanded).
Usage
- Create a Scriptable Object which will be used by the Factory.
Example:
public class NoteConfig : ScriptableObject {
public string note;
public float volume;
}
- Create a factory, which has to implement the interface
IFactory:
Example:
public class NoteFactory : IFactory<NoteConfig>
{
private NoteConfig _creationConfig;
public void SetConfig(NoteConfig config)
{
_creationConfig = config;
}
public GameObject CreateObject()
{
GameObject instantiatedObject = GameObject.Instantiate();
// Note in this example is just a script that uses the config
instantiatedObject.AddComponent<Note>();
Note note = instantiatedObject.getComponent<Note>();
note.UseConfig(_creationConfig);
return instantiatedObject;
}
}
- Create a class that inherits the object pool, using a scriptable object config and a Factory.
Example:
public class NotePool : ObjectPool<NoteConfig, JumpCoinFactory> {}
- Add the pool to an empty object in the scene. This object will now be a Singleton that will create Objects on demand.
Anywhere, you can use these methods to get or return an object to the pool:
GameObject note = NotePool.Instance.GetPooledObject();
NotePool.Instance.ReturnToPool(note);
No comments yet. Be the first!