BestRegionCodeCurrently









How do I use Best Region Code Currently
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonHandler.cs Copy
232     internal IEnumerator PingAvailableRegionsCoroutine(bool connectToBest)
233     {
234         BestRegionCodeCurrently = CloudRegionCode.none;
235         while (PhotonNetwork.networkingPeer.AvailableRegions == null)
236         {
237             if (PhotonNetwork.connectionStateDetailed != PeerState.ConnectingToNameServer && PhotonNetwork.connectionStateDetailed != PeerState.ConnectedToNameServer)
238             {
239                 Debug.LogError("Call ConnectToNameServer to ping available regions.");
240                 yield break; // break if we don't connect to the nameserver at all
241             }
242
243             Debug.Log("Waiting for AvailableRegions. State: " + PhotonNetwork.connectionStateDetailed + " Server: " + PhotonNetwork.Server + " PhotonNetwork.networkingPeer.AvailableRegions " + (PhotonNetwork.networkingPeer.AvailableRegions != null));
244             yield return new WaitForSeconds(0.25f); // wait until pinging finished (offline mode won't ping)
245         }
246
247         if (PhotonNetwork.networkingPeer.AvailableRegions == null || PhotonNetwork.networkingPeer.AvailableRegions.Count == 0)
248         {
249             Debug.LogError("No regions available. Are you sure your appid is valid and setup?");
250             yield break; // break if we don't get regions at all
251         }
252
253         //#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IPHONE)
254         //#pragma warning disable 0162 // the library variant defines if we should use PUN's SocketUdp variant (at all)
255         //if (PhotonPeer.NoSocket)
256         //{
257         // if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
258         // {
259         // Debug.Log("PUN disconnects to re-use native sockets for pining servers and to find the best.");
260         // }
261         // PhotonNetwork.Disconnect();
262         //}
263         //#pragma warning restore 0162
264         //#endif
265
266         PhotonPingManager pingManager = new PhotonPingManager();
267         foreach (Region region in PhotonNetwork.networkingPeer.AvailableRegions)
268         {
269             SP.StartCoroutine(pingManager.PingSocket(region));
270         }
271
272         while (!pingManager.Done)
273         {
274             yield return new WaitForSeconds(0.1f); // wait until pinging finished (offline mode won't ping)
275         }
276
277
278         Region best = pingManager.BestRegion;
279         PhotonHandler.BestRegionCodeCurrently = best.Code;
280         PhotonHandler.BestRegionCodeInPreferences = best.Code;
281
282         Debug.Log("Found best region: " + best.Code + " ping: " + best.Ping + ". Calling ConnectToRegionMaster() is: " + connectToBest);
283
284
285         if (connectToBest)
286         {
287             PhotonNetwork.networkingPeer.ConnectToRegionMaster(best.Code);
288         }
289     }

BestRegionCodeCurrently 114 lượt xem

Gõ tìm kiếm nhanh...