NetInnerComponent
请大家关注我的微博:@NormanLin_BadPixel坏像素
我们在LocationProxyComponent学习笔记有简单介绍过NetInnerComponent,在那里我们介绍了NetInnerComponent的一些变量和方法。不过我们忘记了还有热更层的程序集,在热更的程序集里,还有NetInnerComponent的扩展方法。
NetInnerComponentAwakeSystem
在这里,我们看到,NetInnerComponent注册了2个Awake方法,无参数和带IPEndPoint参数的。并且注册了Update方法。
public static class NetInnerComponentEx
{
public static void Awake(this NetInnerComponent self)
{
self.Awake(NetworkProtocol.TCP);
self.MessagePacker = new MongoPacker();
self.MessageDispatcher = new InnerMessageDispatcher();
self.AppType = self.Entity.GetComponent<StartConfigComponent>().StartConfig.AppType;
}
public static void Awake(this NetInnerComponent self, IPEndPoint ipEndPoint)
{
self.Awake(NetworkProtocol.TCP, ipEndPoint);
self.MessagePacker = new MongoPacker();
self.MessageDispatcher = new InnerMessageDispatcher();
self.AppType = self.Entity.GetComponent<StartConfigComponent>().StartConfig.AppType;
}
public static void Update(this NetInnerComponent self)
{
self.Update();
}
}
我们看到,这里设置了NetInnerComponent的消息打包工具跟消息分发器。并且设置了AppType。
看到InnerMessageDispatcher,大家或许都晕了。怎么有那么多种的消息调度器。
又是InnerMessageDispatcher
又是OuterMessageDispatcher
又是MessageDispatherComponent
又是ActorMessageDispatherComponent的。
还有热更层的MessageDispatherComponent和HotfixMessageDispatcher
到底什么用呦。
这里我简单给打家分一下,让大家不至于太乱。
首先,MessageDispatherComponent跟ActorMessageDispatherComponent都是公共的组件,只不过处理的消息不同,前者处理普通的消息,后者处理Actor消息,因为Actor消息只会在服务器之间发送,所以ActorMessageDispatherComponent只会添加到服务端上,而客户端是没有的。
而OuterMessageDispatcher,我们可以理解为是客户端与服务器通信的消息分发器。因为两者互传,所以两者都有。而热更层的HotfixMessageDispatcher,则是在客户端分发热更相关消息的时候会额外经过HotfixMessageDispatcher。
那不同服务所在服务器之间的通信消息又是用什么调度的呢?这个时候就用到了我们的InnerMessageDispatcher啦。而InnerMessageDispatcher最后会把Actor消息传给ActorMessageDispatherComponent里面处理。