## 3-4.对象池模块 - ObjectModule
对象池较中量级,在客户端开发中是一个经常使用的技术,技术点我相信大家都懂,这里不过多讨论。
使用案例
``` csharp
///
/// Actor对象。
///
public class Actor : ObjectBase
{
///
/// 释放对象。
///
/// 是否是关闭对象池时触发。
protected override void Release(bool isShutdown){}
}
///
/// Actor对象池。
///
private IObjectPool _actorPool;
void Start()
{
//创建允许单次获取的对象池。
_actorPool = GameModule.ObjectPool.CreateSingleSpawnObjectPool(Utility.Text.Format("Actor Instance Pool ({0})", name));
}
///
/// 创建Actor对象。
///
/// Actor对象实例。
public Actor CreateActor()
{
Actor ret = null;
if (_actorPool.CanSpawn())
{
ret = _actorPool.Spawn();
}
else
{
ret = MemoryPool.Acquire();
_actorPool.Register(ret,true);
}
return ret;
}
```