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

39 lines
1.3 KiB
C#

using System.Collections.Generic;
using MongoDB.Bson;
namespace ET.Server
{
public static partial class TransferHelper
{
public static async ETTask TransferAtFrameFinish(Unit unit, ActorId sceneInstanceId, string sceneName)
{
await unit.Fiber().WaitFrameFinish();
await TransferHelper.Transfer(unit, sceneInstanceId, sceneName);
}
public static async ETTask Transfer(Unit unit, ActorId sceneInstanceId, string sceneName)
{
Scene root = unit.Root();
// location加锁
long unitId = unit.Id;
M2M_UnitTransferRequest request = M2M_UnitTransferRequest.Create();
request.OldActorId = unit.GetActorId();
request.Unit = unit.ToBson();
foreach (Entity entity in unit.Components.Values)
{
if (entity is ITransfer)
{
request.Entitys.Add(entity.ToBson());
}
}
unit.Dispose();
await root.GetComponent<LocationProxyComponent>().Lock(LocationType.Unit, unitId, request.OldActorId);
await root.GetComponent<ActorSenderComponent>().Call(sceneInstanceId, request);
}
}
}