我目前有成功的发送一个 actor location 消息 如下
消息定义:
message C2M_SayHello //IActorLocationMessage
{
int32 RpcId = 90;
int64 ActorId = 91;
int64 TargetUnitId = 92;
string Message = 93;
}
handler类
[ActorMessageHandler(AppType.Map)]
public class C2M_SayHelloHandler : AMActorLocationHandler<Unit, C2M_SayHello>
{
protected override async ETTask Run(Unit unit, C2M_SayHello message)
{
//调试进到这个地方
}
}
然后我有个功能,一个战场 Battle。然后给它挂载上 MailBoxComponent 并且添加了定位
await battle.AddComponent<MailBoxComponent>().AddLocation();
然后我有一个战场内消息想直接传给这个 Battle
消息定于:
message Actor_Battle_Step //IActorLocationMessage
{
int32 RpcId = 90;
int64 ActorId = 91;
int64 TargetUnitId = 92;
int32 Step = 93;
}
handler类:
[ActorMessageHandler(AppType.Map)]
public class Actor_Battle_StepHandler : AMActorLocationHandler<Battle, Actor_Battle_Step>
{
protected override async ETTask Run(XxooBattle unit, Actor_Battle_Step message)
{
//调试无法进到这里
}
}
然后我知道actorid就是entity的 instance id。于是下发了instance id 给客户端并 赋值给 Actor_Battle_Step
ETModel.SessionComponent.Instance.Session.Send(new Actor_Battle_Step() { ActorId = message.Battle.BattleActorId }); ;
结果是怎么也无法进入到 Actor_Battle_StepHandler
然后我去看斗地主的案例,发现没有手动设置actorid的地方。
然后它是通过user找到对应想传消息的 Room。
我想我也可以这么处理,但是我更希望实现直接将消息传给任意 Entity。而不是把玩家自身当中介。
断点调了很久,源码读不太懂,无力,麻烦大家了。