/sproto-Unity

A demo show how to use sproto-Csharp in Unity.

Primary LanguageC#MIT LicenseMIT

sproto-Unity

A demo show how to use sproto-Csharp in Unity.

How to send RPC

SprotoType.Handshake.request req = new SprotoType.Handshake.request();
req.uid = uid;
req.token = token;

NetSender.Send<Protocol.Handshake>(req, (_) =>
{
	SprotoType.Handshake.response rsp = _ as SprotoType.Handshake.response;
	if (rsp.result == 0)
	{
	}
});

How to recv RPC

SprotoTypeBase HeartbeatRsp(SprotoTypeBase _)
{
    SprotoType.Heartbeat.request req = _ as SprotoType.Heartbeat.request;
    return null; // can return a response
}

NetReceiver.AddHandler<Protocol.Heartbeat>(HeartbeatRsp);