Loading
How do I use Loading
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: NetworkingPeer.cs
Copy
3113 public void NewSceneLoaded()
3114 {
3115 if (this.loadingLevelAndPausedNetwork)
3116 {
3117 this.loadingLevelAndPausedNetwork = false;
3118 PhotonNetwork.isMessageQueueRunning = true;
3119 }
3120 // Debug.Log("OnLevelWasLoaded photonViewList.Count: " + photonViewList.Count); // Exit Games internal log
3121
3122 List
3123 foreach (KeyValuePair
3124 {
3125 PhotonView view = kvp.Value;
3126 if (view == null)
3127 {
3128 removeKeys.Add(kvp.Key);
3129 }
3130 }
3131
3132 for (int index = 0; index < removeKeys.Count; index++)
3133 {
3134 int key = removeKeys[index];
3135 this.photonViewList.Remove(key);
3136 }
3137
3138 if (removeKeys.Count > 0)
3139 {
3140 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
3141 Debug.Log("New level loaded. Removed " + removeKeys.Count + " scene view IDs from last level.");
3142 }
3143 }
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 }
File name: PhotonNetwork.cs
Copy
2479 internal static void RPC(PhotonView view, string methodName, PhotonTargets target, bool encrypt, params object[] parameters)
2480 {
2481 if (!VerifyCanUseNetwork())
2482 {
2483 return;
2484 }
2485
2486 if (room == null)
2487 {
2488 Debug.LogWarning("Cannot send RPCs in Lobby! RPC dropped.");
2489 return;
2490 }
2491
2492 if (networkingPeer != null)
2493 {
2494 networkingPeer.RPC(view, methodName, target, encrypt, parameters);
2495 }
2496 else
2497 {
2498 Debug.LogWarning("Could not execute RPC " + methodName + ". Possible scene loading in progress?");
2499 }
2500 }
File name: PhotonNetwork.cs
Copy
2505 internal static void RPC(PhotonView view, string methodName, PhotonPlayer targetPlayer, bool encrpyt, params object[] parameters)
2506 {
2507 if (!VerifyCanUseNetwork())
2508 {
2509 return;
2510 }
2511
2512 if (room == null)
2513 {
2514 Debug.LogWarning("Cannot send RPCs in Lobby, only processed locally");
2515 return;
2516 }
2517
2518 if (player == null)
2519 {
2520 Debug.LogError("Error; Sending RPC to player null! Aborted \"" + methodName + "\"");
2521 }
2522
2523 if (networkingPeer != null)
2524 {
2525 networkingPeer.RPC(view, methodName, targetPlayer, encrpyt, parameters);
2526 }
2527 else
2528 {
2529 Debug.LogWarning("Could not execute RPC " + methodName + ". Possible scene loading in progress?");
2530 }
2531 }
File name: PhotonNetwork.cs
Copy
2652 public static void LoadLevel(int levelNumber)
2653 {
2654 networkingPeer.SetLevelInPropsIfSynced(levelNumber);
2655
2656 PhotonNetwork.isMessageQueueRunning = false;
2657 networkingPeer.loadingLevelAndPausedNetwork = true;
2658 Application.LoadLevel(levelNumber);
2659 }
File name: PhotonNetwork.cs
Copy
2678 public static void LoadLevel(string levelName)
2679 {
2680 networkingPeer.SetLevelInPropsIfSynced(levelName);
2681
2682 PhotonNetwork.isMessageQueueRunning = false;
2683 networkingPeer.loadingLevelAndPausedNetwork = true;
2684 Application.LoadLevel(levelName);
2685 }
File name: PhotonView.cs
Copy
295 protected internal void OnDestroy()
296 {
297 if (!this.destroyedByPhotonNetworkOrQuit)
298 {
299 PhotonNetwork.networkingPeer.LocalCleanPhotonView(this);
300 }
301
302 if (!this.destroyedByPhotonNetworkOrQuit && !Application.isLoadingLevel)
303 {
304 if (this.instantiationId > 0)
305 {
306 // if this viewID was not manually assigned (and we're not shutting down or loading a level), you should use PhotonNetwork.Destroy() to get rid of GOs with PhotonViews
307 Debug.LogError("OnDestroy() seems to be called without PhotonNetwork.Destroy()?! GameObject: " + this.gameObject + " Application.isLoadingLevel: " + Application.isLoadingLevel);
308 }
309 else
310 {
311 // this seems to be a manually instantiated PV. if it's local, we could warn if the ID is not in the allocated-list
312 if (this.viewID <= 0)
313 {
314 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is 0. Was it ever (manually) set?", this));
315 }
316 else if (this.isMine && !PhotonNetwork.manuallyAllocatedViewIds.Contains(this.viewID))
317 {
318 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is local (isMine) but not in manuallyAllocatedViewIds list. Use UnAllocateViewID() after you destroyed the PV.", this));
319 }
320 }
321 }
322 }
File name: frmSplash.cs
Copy
19 private void timer1_Tick(object sender, EventArgs e)
20 {
21 frmLogin frm = new frmLogin();
22 progressBar1.Visible = true;
23
24 this.progressBar1.Value = this.progressBar1.Value + 2;
25 if (this.progressBar1.Value == 10)
26 {
27 label3.Text = "Reading modules..";
28 }
29 else if (this.progressBar1.Value == 20)
30 {
31 label3.Text = "Turning on modules.";
32 }
33 else if (this.progressBar1.Value == 40)
34 {
35 label3.Text = "Starting modules..";
36 }
37 else if (this.progressBar1.Value == 60)
38 {
39 label3.Text = "Loading modules..";
40 }
41 else if (this.progressBar1.Value == 80)
42 {
43 label3.Text = "Done Loading modules..";
44 }
45 else if (this.progressBar1.Value == 100)
46 {
47 frm.Show();
48 timer1.Enabled = false;
49 this.Hide();
50 }
51 }
Download file with original file name:Loading
Loading 134 lượt xem
Gõ tìm kiếm nhanh...