饭太稀
This commit is contained in:
22
Hotfix/Inner/Addressable/G2M_RequestAddressableIdHandler.cs
Normal file
22
Hotfix/Inner/Addressable/G2M_RequestAddressableIdHandler.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.Network.Route;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed class G2M_RequestAddressableIdHandler : RouteRPC<Scene, G2M_RequestAddressableId, M2G_ResponseAddressableId>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2M_RequestAddressableId request, M2G_ResponseAddressableId response, Action reply)
|
||||
{
|
||||
// 1、因为是测试代码,所以默认每次请求这个协议我都创建一个新的Unit来做Addressable。
|
||||
var unit = Entity.Create<Unit>(scene, false, true);
|
||||
// 2、给Unit添加AddressableMessageComponent组件,并执行Register(),向AddressableScene注册自己当前的位置。
|
||||
await unit.AddComponent<AddressableMessageComponent>().Register();
|
||||
// 3、返回给Gate服务器AddressableId
|
||||
response.AddressableId = unit.Id;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
15
Hotfix/Inner/G2A_TestMessageHandler.cs
Normal file
15
Hotfix/Inner/G2A_TestMessageHandler.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class G2A_TestMessageHandler : Route<Scene,G2A_TestMessage>
|
||||
{
|
||||
protected override async FTask Run(Scene entity, G2A_TestMessage message)
|
||||
{
|
||||
|
||||
|
||||
Log.Debug($"G2A_TestMessageHandler :{message.Tag}");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
19
Hotfix/Inner/G2A_TestRequestHandler.cs
Normal file
19
Hotfix/Inner/G2A_TestRequestHandler.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class G2A_TestRequestHandler : RouteRPC<Scene, G2A_TestRequest, G2A_TestResponse>
|
||||
{
|
||||
private static int Count;
|
||||
protected override async FTask Run(Scene entity, G2A_TestRequest request, G2A_TestResponse response, Action reply)
|
||||
{
|
||||
if (++Count % 1000000 == 0)
|
||||
{
|
||||
Log.Debug($"count:1000000");
|
||||
}
|
||||
// Log.Debug($"{Count}");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed class G2Chat_CreateRouteRequestHandler : RouteRPC<Scene, G2Chat_CreateRouteRequest, Chat2G_CreateRouteResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2Chat_CreateRouteRequest request, Chat2G_CreateRouteResponse response, Action reply)
|
||||
{
|
||||
// 接收到Gate消息后,首先建立一个实体用来后面接收Route消息。
|
||||
// 这里就拿ChatUnit来做这个。
|
||||
var chatUnit = Entity.Create<ChatUnit>(scene, true, true);
|
||||
// 把Gate传递过来的RouteId保存住,以便后面可以直接给Gate发送消息。
|
||||
// 例如断线等操作,都可以通过这个GateRouteId发送到Gate的Session上。
|
||||
chatUnit.GateRouteId = request.GateRouteId;
|
||||
// 把chatUnit的RunTimeId发送给Gate。
|
||||
// 正如之前所说任何实体的RunTimeId都可以当做RouteId使用。
|
||||
response.ChatRouteId = chatUnit.RouteId;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
17
Hotfix/Inner/SubScene/G2M_CreateSubSceneRequestHandler.cs
Normal file
17
Hotfix/Inner/SubScene/G2M_CreateSubSceneRequestHandler.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class G2M_CreateSubSceneRequestHandler : RouteRPC<Scene, G2M_CreateSubSceneRequest, M2G_CreateSubSceneResponse>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2M_CreateSubSceneRequest request, M2G_CreateSubSceneResponse response, Action reply)
|
||||
{
|
||||
// 下面的SceneType传的是666,其实并没有这个类型,这个是我随便写的。
|
||||
var subScene = Scene.CreateSubScene(scene, 6666);
|
||||
// 返回subScene的运行时id
|
||||
response.SubSceneRouteId = subScene.RouteId;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.Network.Route;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public sealed class G2SubScene_AddressableIdRequestHandler : RouteRPC<SubScene, G2SubScene_AddressableIdRequest, SubScene2G_AddressableIdResponse>
|
||||
{
|
||||
protected override async FTask Run(SubScene subScene, G2SubScene_AddressableIdRequest request, SubScene2G_AddressableIdResponse response, Action reply)
|
||||
{
|
||||
Log.Debug($"G2SubScene_AddressableIdRequestHandler {subScene.SceneType}");
|
||||
// 1、因为是测试代码,所以默认每次请求这个协议我都创建一个新的Unit来做Addressable。
|
||||
var unit = Entity.Create<Unit>(subScene, false, true);
|
||||
// 2、给Unit添加AddressableMessageComponent组件,并执行Register(),向AddressableScene注册自己当前的位置。
|
||||
await unit.AddComponent<AddressableMessageComponent>().Register();
|
||||
// 3、返回给Gate服务器AddressableId
|
||||
response.AddressableId = unit.Id;
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
13
Hotfix/Inner/SubScene/G2SubScene_SentMessageHandler.cs
Normal file
13
Hotfix/Inner/SubScene/G2SubScene_SentMessageHandler.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network.Interface;
|
||||
|
||||
namespace Fantasy;
|
||||
|
||||
public class G2SubScene_SentMessageHandler : Route<Scene, G2SubScene_SentMessage>
|
||||
{
|
||||
protected override async FTask Run(Scene scene, G2SubScene_SentMessage message)
|
||||
{
|
||||
Log.Debug($"接受到来自Gate的消息 SceneType:{scene.SceneType} Message:{message.Tag}");
|
||||
await FTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user