欢迎光临散文网 会员登陆 & 注册

UnityGameFramework接入Sproto协议

2023-02-19 16:15 作者:伪乱  | 我要投稿

先说一下我踩的坑。我以为RPC会自己管理session。然后想错了。所以做了很多无用的事。想起之后才解决了这个问题。

UGF的network生命周期很简单。、

获得头包长度,解析头包。获得真正包体的长度,解析包体。

大致的目录结构

基类Packet

PacketID,c2s 10000+tag

                s2c 20000+tag



序列化

var bytes = clientRequest.Invoke(packetBase.Id-10000,packetBase.requestObj,session);



反序列化

var info= client.Dispatch(bytes);
PacketBase packet = null;
if (info.type==SprotoRpc.RpcType.REQUEST)
{
   Type type = GetServerToClientPacketType(20000 + info.tag.Value);
   if (type==null)
   {
       Debug.Log("未获得类型");
   }
   packet=ReferencePool.Acquire(type) as PacketBase;
}
else
{
   Type type = GetServerToClientPacketType(10000 + m_SissionTags[info.session.Value]);
   packet=ReferencePool.Acquire(type) as PacketBase;
   packet.responseObj = info.responseObj;
}
return packet;


UnityGameFramework接入Sproto协议的评论 (共 条)

分享到微博请遵守国家法律