ConnectToBestCloudServer
How do I use Connect To Best Cloud Server
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
1155 | return ConnectToBestCloudServer(gameVersion); | 1 |
1231 | public static bool ConnectToBestCloudServer(string gameVersion) | 2 |
File name: PhotonNetwork.cs
Copy
1109 /// - Invalid AppId (calls: OnFailedToConnectToPhoton(). check exact AppId value)
1110 /// - Network issues (calls: OnFailedToConnectToPhoton())
1111 /// - Invalid region (calls: OnConnectionFail() with DisconnectCause.InvalidRegion)
1112 /// - Subscription CCU limit reached (calls: OnConnectionFail() with DisconnectCause.MaxCcuReached. also calls: OnPhotonMaxCccuReached())
1118 public static bool ConnectUsingSettings(string gameVersion)
1119 {
1120 if (PhotonServerSettings == null)
1121 {
1122 Debug.LogError("Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: " + serverSettingsAssetFile);
1123 return false;
1124 }
1125
1126 SwitchToProtocol(PhotonServerSettings.Protocol);
1127 networkingPeer.SetApp(PhotonServerSettings.AppID, gameVersion);
1128
1129 if (PhotonServerSettings.HostType == ServerSettings.HostingOption.OfflineMode)
1130 {
1131 offlineMode = true;
1132 return true;
1133 }
1134
1135 if (offlineMode)
1136 {
1137 // someone can set offlineMode in code and then call ConnectUsingSettings() with non-offline settings. Warning for that case:
1138 Debug.LogWarning("ConnectUsingSettings() disabled the offline mode. No longer offline.");
1139 }
1140
1141 offlineMode = false; // Cleanup offline mode
1142 isMessageQueueRunning = true;
1143 networkingPeer.IsInitialConnect = true;
1144
1145 if (PhotonServerSettings.HostType == ServerSettings.HostingOption.SelfHosted)
1146 {
1147 networkingPeer.IsUsingNameServer = false;
1148 networkingPeer.MasterServerAddress = (PhotonServerSettings.ServerPort == 0) ? PhotonServerSettings.ServerAddress : PhotonServerSettings.ServerAddress + ":" + PhotonServerSettings.ServerPort;
1149
1150 return networkingPeer.Connect(networkingPeer.MasterServerAddress, ServerConnection.MasterServer);
1151 }
1152
1153 if (PhotonServerSettings.HostType == ServerSettings.HostingOption.BestRegion)
1154 {
1155 return ConnectToBestCloudServer(gameVersion);
1156 }
1157
1158 return networkingPeer.ConnectToRegionMaster(PhotonServerSettings.PreferredRegion);
1159 }
File name: PhotonNetwork.cs
Copy
1213 /// The ping result can be overridden via PhotonNetwork.OverrideBestCloudServer(..)
1221 /// - Invalid AppId (calls: OnFailedToConnectToPhoton(). check exact AppId value)
1222 /// - Network issues (calls: OnFailedToConnectToPhoton())
1223 /// - Invalid region (calls: OnConnectionFail() with DisconnectCause.InvalidRegion)
1224 /// - Subscription CCU limit reached (calls: OnConnectionFail() with DisconnectCause.MaxCcuReached. also calls: OnPhotonMaxCccuReached())
1231 public static bool ConnectToBestCloudServer(string gameVersion)
1232 {
1233 if (PhotonServerSettings == null)
1234 {
1235 Debug.LogError("Can't connect: Loading settings failed. ServerSettings asset must be in any 'Resources' folder as: " + PhotonNetwork.serverSettingsAssetFile);
1236 return false;
1237 }
1238
1239 if (PhotonServerSettings.HostType == ServerSettings.HostingOption.OfflineMode)
1240 {
1241 return PhotonNetwork.ConnectUsingSettings(gameVersion);
1242 }
1243
1244 networkingPeer.IsInitialConnect = true;
1245 networkingPeer.SetApp(PhotonServerSettings.AppID, gameVersion);
1246
1247 CloudRegionCode bestFromPrefs = PhotonHandler.BestRegionCodeInPreferences;
1248 if (bestFromPrefs != CloudRegionCode.none)
1249 {
1250 Debug.Log("Best region found in PlayerPrefs. Connecting to: " + bestFromPrefs);
1251 return networkingPeer.ConnectToRegionMaster(bestFromPrefs);
1252 }
1253
1254 bool couldConnect = PhotonNetwork.networkingPeer.ConnectToNameServer();
1255 return couldConnect;
1256 }
ConnectToBestCloudServer 108 lượt xem
Gõ tìm kiếm nhanh...