Photon Network多次调用Service();

问题描述 投票:0回答:1

根据以下链接https://doc.photonengine.com/realtime/current/reference/performance-tips建议多次调用service(),但我想知道多少次比较理想?因为在我的应用程序中这导致我退出游戏。

private void ServiceLoop()
    {
        int timeMill = 20000;
        while (isServiceRunning)
        {
            if (PhotonNetwork.NetworkingClient != null)
            {
                PhotonNetwork.NetworkingClient.Service();

                // if (PhotonNetwork.NetworkingClient.LoadBalancingPeer.SendOutgoingCommands())
                // {
                //     Debug.LogException(new       System.Exception("LoadBalancingPeer.SendOutgoingCommands()"), this);
                //     PhotonNetwork.SendAllOutgoingCommands();
                // }

                System.Threading.Thread.Sleep(timeMill);
            }
        }
    }

我们预计多次调用 service() 时光子断开会更少。

performance unity-game-engine photon photon-pun
1个回答
0
投票

具体应该调用 Service() 多少次取决于您的游戏,但通常每秒 10-20 次是最好的。

您对 timeMill 的 20000 值太高了。如果您调用它的频率不超过每 20 秒一次,那么您肯定会遇到超时断开连接,因为服务器会断开在 5-10 秒内不发送任何生命迹象的客户端的连接,并且客户端仅从在 Service() 内部(或者更确切地说 SendOutgoingCommands(),它由 Service() 调用,但也可以由您的代码调用)。

将 timeMill 的值更改为 100 应该可以解决该问题。

© www.soinside.com 2019 - 2024. All rights reserved.