Files
TEngine/Assets/GameScripts/DotNet/Hotfix/Server/Demo/Gate/C2G_EnterMapHandler.cs
ALEXTANG 336d4b2eb9 [+] 接入ET8服务端
[+] 接入ET8服务端
2023-07-13 12:23:48 +08:00

26 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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