mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ActorMessageLocationHandler(SceneType.Map)]
|
||||
public class C2M_TransferMapHandler : ActorMessageLocationHandler<Unit, C2M_TransferMap, M2C_TransferMap>
|
||||
{
|
||||
protected override async ETTask Run(Unit unit, C2M_TransferMap request, M2C_TransferMap response)
|
||||
{
|
||||
await ETTask.CompletedTask;
|
||||
|
||||
string currentMap = unit.Scene().Name;
|
||||
string toMap = null;
|
||||
if (currentMap == "Map1")
|
||||
{
|
||||
toMap = "Map2";
|
||||
}
|
||||
else
|
||||
{
|
||||
toMap = "Map1";
|
||||
}
|
||||
|
||||
StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.GetBySceneName(unit.Fiber().Zone, toMap);
|
||||
|
||||
TransferHelper.TransferAtFrameFinish(unit, startSceneConfig.ActorId, toMap).Coroutine();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 09e1381365665c14aaa410513c72dbb1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace ET.Server
|
||||
{
|
||||
[ActorMessageHandler(SceneType.Map)]
|
||||
public class M2M_UnitTransferRequestHandler: ActorMessageHandler<Scene, M2M_UnitTransferRequest, M2M_UnitTransferResponse>
|
||||
{
|
||||
protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response)
|
||||
{
|
||||
UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
|
||||
Unit unit = MongoHelper.Deserialize<Unit>(request.Unit);
|
||||
|
||||
unitComponent.AddChild(unit);
|
||||
unitComponent.Add(unit);
|
||||
|
||||
foreach (byte[] bytes in request.Entitys)
|
||||
{
|
||||
Entity entity = MongoHelper.Deserialize<Entity>(bytes);
|
||||
unit.AddComponent(entity);
|
||||
}
|
||||
|
||||
unit.AddComponent<MoveComponent>();
|
||||
unit.AddComponent<PathfindingComponent, string>(scene.Name);
|
||||
unit.Position = new float3(-10, 0, -10);
|
||||
|
||||
unit.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.OrderedMessage);
|
||||
|
||||
// 通知客户端开始切场景
|
||||
M2C_StartSceneChange m2CStartSceneChange = new() { SceneInstanceId = scene.InstanceId, SceneName = scene.Name };
|
||||
MessageHelper.SendToClient(unit, m2CStartSceneChange);
|
||||
|
||||
// 通知客户端创建My Unit
|
||||
M2C_CreateMyUnit m2CCreateUnits = new();
|
||||
m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);
|
||||
MessageHelper.SendToClient(unit, m2CCreateUnits);
|
||||
|
||||
// 加入aoi
|
||||
unit.AddComponent<AOIEntity, int, float3>(9 * 1000, unit.Position);
|
||||
|
||||
// 解锁location,可以接收发给Unit的消息
|
||||
await scene.Root().GetComponent<LocationProxyComponent>().UnLock(LocationType.Unit, unit.Id, request.OldActorId, unit.GetActorId());
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8e9b12c47eb5ac41b42a6b83817f1d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6fe1b54e7a5a88243a60c501d7a71979
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user