Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mr-sb/objectpool
The Unity object pooling can load and cache all objects inherited from UnityEngine.Object, and can easily expand the loading method, such as loading objects from AssetBundle. And contains CommonPool to cache other type objects.
https://github.com/mr-sb/objectpool
cache objectpool script unity
Last synced: about 2 months ago
JSON representation
The Unity object pooling can load and cache all objects inherited from UnityEngine.Object, and can easily expand the loading method, such as loading objects from AssetBundle. And contains CommonPool to cache other type objects.
- Host: GitHub
- URL: https://github.com/mr-sb/objectpool
- Owner: Mr-sB
- License: mit
- Created: 2020-04-16T07:23:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T04:54:19.000Z (4 months ago)
- Last Synced: 2024-08-28T05:51:41.112Z (4 months ago)
- Topics: cache, objectpool, script, unity
- Language: C#
- Homepage:
- Size: 37.1 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ObjectPool
The Unity object pooling can load and cache all objects inherited from UnityEngine.Object, and can easily expand the loading method, such as loading objects from AssetBundle.
And contains CommonPool to cache other type objects.# Feature
* `ObjectPool` can load and cache all objects inherited from `UnityEngine.Object`.
* For `CommonPool`, build in ListPool, QueuePool, StackPool, HashSetPool, DictionaryPool to use.
* Unused assets/objects and `PoolItem` will auto destroy by `DeleteTime`. If `DeleteTime` is -1, they will not auto destroy.
* `LoadMode.Resource` to cache from Resources folder.
* `LoadMode.Custom` to cache from anywhere by call `ObjectPool.Instance.RegisterCustomPoolItem` function first.
* If you cache `GameObject`, you can implement `ISpawnHandler` and `IDisposeHandler` interfaces to listen spawn and dispose actions.
```c#
public interface ISpawnHandler
{
void OnSpawn();
}
public interface IDisposeHandler
{
void OnDispose();
}
```
Or you can add listener from `ObjectPoolItemKey.SpawnEvent` and `ObjectPoolItemKey.DisposeEvent`.
```c#
public event Action SpawnEvent;
public event Action DisposeEvent;
```
* Basically does not consume extra memory and GC.# Note
* If you want to cache Object from `AssetBundle`, maybe you can use [AssetBundleManager](https://github.com/Mr-sB/AssetBundleManager)(Open source) to manage your AssetBundles.
```c#
public ObjectPoolItem(Type assetType, ObjectPool.LoadMode loadMode, string bundleName, string assetName, DeleteTime deleteTime) : base(deleteTime)
{
...
switch (mLoadMode)
{
case ObjectPool.LoadMode.Resource:
OriginAsset = Resources.Load(assetName, assetType);
break;
case ObjectPool.LoadMode.Custom:
break;
// MARK: Use AssetBundleManager to load asset.
case ObjectPool.LoadMode.AssetBundle:
OriginAsset = AssetBundleManager.GetAsset(assetType, bundleName, assetName);
break;
// MARK: Add yourself load methods
}
...
}
```