Photon Unity如何保证RPC发送成功?

How to ensure RPC was sent successfully in Photon Unity?

我正在使用 Photon 和 Unity3D 引擎构建多人游戏。 我正在使用 photonView.RPC 在客户端之间发送数据和值。但有时由于网络问题,发送的RPC在客户端执行失败。

有什么方法可以从客户端(发送 RPC 的人)那里检查 RPC 是否已成功发送,如果没有,则再次发送 RPC?

从概念上讲,唯一的方法是,

A sends the message, with a identity code (say, "321321777")

A waits for confirmation...

B receives the messsage

B sends a message "I received 321321777"

这真的是你能做的。请注意,这引入了 超时 的概念。上面其实更像这样...

A sends the message, with a identity code (say, "321321777")

A waits for confirmation...

If no confirmation after (say) 0.5 seconds, send it again. Keep doing that.

B receives the messsage. The label is 321321777

B sends a message "I received 321321777"

Any more copies of "321321777" received by B, B ignores it. But: if multiple "321321777" received by B, B does again send more and more confirmation messages for "321321777"

值得注意的是,作为一般规则,"video games don't work like this."通常你每秒发送数以亿计的位置(或其他),如果有几个被遗漏 - 没关系。

也不要忘记 Unity 网络 "reliable sending" 无论如何都会为您服务 - "PUN" 中可能有这样的概念。