123456789101112131415161718192021222324252627 |
- namespace ET.Server
- {
- [MessageHandler(SceneType.Game)]
- public class C2G_EnterMapHandler : AMRpcHandler<C2G_EnterMap, G2C_EnterMap>
- {
- protected override async ETTask Run(Session session, C2G_EnterMap request, G2C_EnterMap response)
- {
- Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
- // 在Game上动态创建一个Map Scene,把Unit从DB中加载放进来,然后传送到真正的Map中,这样登陆跟传送的逻辑就完全一样了
- GameMapComponent gateMapComponent = player.AddComponent<GameMapComponent>();
- gateMapComponent.Scene = await SceneFactory.CreateServerScene(gateMapComponent, player.Id, IdGenerater.Instance.GenerateInstanceId(), gateMapComponent.DomainZone(), "GateMap", SceneType.Map);
- Scene scene = gateMapComponent.Scene;
-
- // 这里可以从DB中加载Unit
- Unit unit = UnitFactory.Create(scene, player.Id, UnitType.Player);
- unit.AddComponent<UnitGateComponent, long>(session.InstanceId);
-
- StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.GetBySceneName(session.DomainZone(), "Map1");
- response.MyId = player.Id;
- // 等到一帧的最后面再传送,先让G2C_EnterMap返回,否则传送消息可能比G2C_EnterMap还早
- TransferHelper.TransferAtFrameFinish(unit, startSceneConfig.InstanceId, startSceneConfig.Name).Coroutine();
- }
- }
- }
|