Unity ET 框架 分布式网络消息通信 详
DEMO配表



ActorMessageSenderComponent.Instance.Send 会将消息体或流完整的发到 对应 进程
再通过NetInnerComponent处理
ActorMessageSenderComponent.Instance.Call 会将消息体或流完整的发到 对应 进程 再通过NetInnerComponent处理
DEMO 流程
当客户端发送登录请求 到Realm

随机拿到Gate对应的SceneConfig后 用其InstanceId(包含了Gate内网的进程号)对Gate 进程 的内网进行通讯
ActorMessageSenderComponent.Instance.Call

拿到目标内网进程 从Realm内网建立 拿到对应编号的Channel 与 Gate内网 没有就连接 并发送消息
ProcessActorId processActorId = new ProcessActorId(actorId);
processActorId.Process 对应 了 目标(Gate)
processActorId.ActorId 对应 将 当前进程注入 修改 为了回执
实 ActorId 是 Gate 的 SceneConfig InstanceId
虚 ActorId 是 为了Gate的内网收到消息后 知道 消息是由哪个内网进程发出
当Gate服务端内网收到消息时 通过 SessionStreamDispatcherServerInner 分发 处理 R2G_GetLoginKey
G2R_GetLoginKey 是内网消息体

虚 ActorId 是 为了 拿到 回执 的 对应内网(Realm)将 InnerMessageDispatcherHelper.HandleIActorRequest 处理完 拿到 对应 IActorResponse 再拿到来源或与来源(Realm)建立连接 发回
内网消息 分发 的 实 ActorId 为 没什么用 这里 对应 Gate 的 SceneConfig 的 InstanceId
Realm服务器 内网拿到 后 通过 SessionStreamDispatcherServerInner 分发 处理 G2R_GetLoginKey

将对应的tcs(类似TaskCompetedTask)SetResult();

await 完成 得到 Key 返回给客户端
当 客户端 发送 进入 地图 的 消息 外网消息解析 常规


MessageHelper.SendToClient 最终调用
ActorMessageSenderComponent.Instance.Send(actorId, message);
actorId 为 客户端 连接的 Gate 的 Session 的 InstanceId
当Gate服务端内网收到消息时 通过 SessionStreamDispatcherServerInner 处理 自行处理 拿到 Session 发送
根据 发来的ActorId 拿到原来 的 Session 发送 (这里看上去鸡肋 但转移Map时有用 这也是为什么不在C2G_EnterMapHandler直接拿到Session 返回的原因)

M2M_UnitTransferRequest 将 Unit 转移到对应地图Map
await LocationProxyComponent.Instance.Lock
调用 ActorMessageSenderComponent.Instance.Call 发送 ObjectLockRequest 给 Location 内网 收到后调用


锁住unit的Id 在time秒后解锁 解锁后 会 记入定位字典
协程中 若时间到之前 已经 被 UnLock lockInfo被Dispose InstanceId置为0 返回退出
调用 ActorMessageSenderComponent.Instance.Call 发送 M2M_UnitTransferRequest 给 对应 Map 内网 收到后调用

后 回执 给 Gate 后 Gate 处理

将对应的tcs(类似TaskCompetedTask)SetResult();

await 完成 解锁 Dispose Unit

解锁时注入的response.NewInstanceId 是 Unit 所在 Map 的 进程号 因此可以 通过 此NewInstanceId知道Unit重设后所在内网进程
而最新unit.Id对应的InstanceId可以通过 LocationProxyComponent.Instance.Get 获得
ActorLocationSenderComponent消息通讯会自动获得
当客户端切换地图时
发送消息体 C2M_TransferMap 是 IActorLocationMessage 内网消息体 Gate外网接收


询问Location服务器 要 Unit 当前的 InstanceId 以获得对应 内网进程

再发送给 对应 的 Map 内网服务(NetInnerComponent) 去接收 C2M_TransferMap 的流
再 用 Map 内网服务 SessionStreamDispatcherServerInner 去处理 内网方式

Map 处理 下

转移到另一个内网Map服务

会拿到客户端与Gate连接的Session 的 InstanceId 通过ActorMessageSenderComponent.Instance.Send方式将 消息体发送给Gate内网 再由 Gate内网 SessionStreamDispatcherServerInner 解析 M2C_StartSceneChange 外网消息体

回执给Gate结果
当客户端右键行走
发送 C2M_PathfindingResult 在 连接的Gate 外网 SessionStreamDispatcherServerOuter 分发
将消息发送给 unit 所在 服务对应内网进程 (Map)
然后 Map 内网 收到后 SessionStreamDispatcherServerInner 分发
检测为内网处理的消息 IActorLocationMessage 继承 IActorRequest

再回执给 Gate 完成