接下来要实现资源处理的模块,资源处理使用异步的方式,需要用到事件委托和引用池。
引用池:新的类对象会消耗内存,所以引入引用池概念,将类对象循环使用节约内存开销。
大量使用的类对象,要使用引用池。
IReference接口:使用引用池的类必须是引用类型,定义引用类,需要继承该接口,并完整实现Clear方法。
ReferenceCollection类:
ReferencePoolInfo类:
ReferencePool类:
事件订阅:以生成实体为例。
// 订阅事件。
Entry.Event.Subscribe(ShowEntitySuccessEventArgs.EventId, OnShowEntitySuccess);
// 事件回调。
protected virtual void OnShowEntitySuccess(object sender, GameEventArgs e)
{
ShowEntitySuccessEventArgs ne = (ShowEntitySuccessEventArgs)e;
if (ne.EntityLogicType == typeof(Pawn))
{
pawn = (Pawn)ne.Entity.Logic;
}
}// 声明显示实体成功事件处理器。
private EventHandler<ShowEntitySuccessEventArgs> m_Sho