ProgressBar
How do I use Progress Bar
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonConverter.cs
Copy
18 public static void RunConversion()
19 {
20 //Ask if user has made a backup.
21 int option = EditorUtility.DisplayDialogComplex("Conversion", "Attempt automatic conversion from Unity Networking to Photon Unity Networking \"PUN\"?", "Yes", "No!", "Pick Script Folder");
22 switch (option)
23 {
24 case 0:
25 break;
26 case 1:
27 return;
28 case 2:
29 PickFolderAndConvertScripts();
30 return;
31 default:
32 return;
33 }
34
35 //REAAAALY?
36 bool result = EditorUtility.DisplayDialog("Conversion", "Disclaimer: The code conversion feature is quite crude, but should do it's job well (see the sourcecode). A backup is therefore strongly recommended!", "Yes, I've made a backup: GO", "Abort");
37 if (!result)
38 {
39 return;
40 }
41 Output(EditorApplication.timeSinceStartup + " Started conversion of Unity networking -> Photon");
42
43 //Ask to save current scene (optional)
44 EditorApplication.SaveCurrentSceneIfUserWantsTo();
45
46 EditorUtility.DisplayProgressBar("Converting..", "Starting.", 0);
47
48 //Convert NetworkViews to PhotonViews in Project prefabs
49 //Ask the user if we can move all prefabs to a resources folder
50 bool movePrefabs = EditorUtility.DisplayDialog("Conversion", "Can all prefabs that use a PhotonView be moved to a Resources/ folder? You need this if you use Network.Instantiate.", "Yes", "No");
51
52
53 string[] prefabs = Directory.GetFiles("Assets/", "*.prefab", SearchOption.AllDirectories);
54 foreach (string prefab in prefabs)
55 {
56 EditorUtility.DisplayProgressBar("Converting..", "Object:" + prefab, 0.6f);
57
58 Object[] objs = (Object[])AssetDatabase.LoadAllAssetsAtPath(prefab);
59 int converted = 0;
60 foreach (Object obj in objs)
61 {
62 if (obj != null && obj.GetType() == typeof(GameObject))
63 converted += ConvertNetworkView(((GameObject)obj).GetComponents
64 }
65 if (movePrefabs && converted > 0)
66 {
67 //This prefab needs to be under the root of a Resources folder!
68 string path = prefab.Replace("\\", "/");
69 int lastSlash = path.LastIndexOf("/");
70 int resourcesIndex = path.LastIndexOf("/Resources/");
71 if (resourcesIndex != lastSlash - 10)
72 {
73 if (path.Contains("/Resources/"))
74 {
75 Debug.LogWarning("Warning, prefab [" + prefab + "] was already in a resources folder. But has been placed in the root of another one!");
76 }
77 //This prefab NEEDS to be placed under a resources folder
78 string resourcesFolder = path.Substring(0, lastSlash) + "/Resources/";
79 EnsureFolder(resourcesFolder);
80 string newPath = resourcesFolder + path.Substring(lastSlash + 1);
81 string error = AssetDatabase.MoveAsset(prefab, newPath);
82 if (error != "")
83 Debug.LogError(error);
84 Output("Fixed prefab [" + prefab + "] by moving it into a resources folder.");
85 }
86 }
87 }
88
89 //Convert NetworkViews to PhotonViews in scenes
90 string[] sceneFiles = Directory.GetFiles("Assets/", "*.unity", SearchOption.AllDirectories);
91 foreach (string sceneName in sceneFiles)
92 {
93 EditorApplication.OpenScene(sceneName);
94 EditorUtility.DisplayProgressBar("Converting..", "Scene:" + sceneName, 0.2f);
95
96 int converted2 = ConvertNetworkView((NetworkView[])GameObject.FindObjectsOfType(typeof(NetworkView)), true);
97 if (converted2 > 0)
98 {
99 //This will correct all prefabs: The prefabs have gotten new components, but the correct ID's were lost in this case
100 PhotonViewHandler.HierarchyChange(); //TODO: most likely this is triggered on change or on save
101
102 Output("Replaced " + converted2 + " NetworkViews with PhotonViews in scene: " + sceneName);
103 EditorApplication.SaveScene(EditorApplication.currentScene);
104 }
105
106 }
107
108 //Convert C#/JS scripts (API stuff)
109 List
110
111 EditorUtility.DisplayProgressBar("Converting..", "Scripts..", 0.9f);
112 ConvertScripts(scripts);
113
114 Output(EditorApplication.timeSinceStartup + " Completed conversion!");
115 EditorUtility.ClearProgressBar();
116
117 EditorUtility.DisplayDialog("Completed the conversion", "Don't forget to add \"PhotonNetwork.ConnectWithDefaultSettings();\" to connect to the Photon server before using any multiplayer functionality.", "OK");
118 }
File name: PhotonEditor.cs
Copy
792 protected virtual void RegisterWithEmail(string email)
793 {
794 EditorUtility.DisplayProgressBar(CurrentLang.ConnectionTitle, CurrentLang.ConnectionInfo, 0.5f);
795 var client = new AccountService();
796 client.RegisterByEmail(email, RegisterOrigin); // this is the synchronous variant using the static RegisterOrigin. "result" is in the client
797
798 EditorUtility.ClearProgressBar();
799 if (client.ReturnCode == 0)
800 {
801 PhotonEditor.Current.UseCloud(client.AppId, 0);
802 PhotonEditor.Save();
803 this.ReApplySettingsToWindow();
804 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
805 }
806 else
807 {
808 if (client.Message.Contains(CurrentLang.EmailInUseLabel))
809 {
810 this.photonSetupState = PhotonSetupStates.EmailAlreadyRegistered;
811 }
812 else
813 {
814 EditorUtility.DisplayDialog(CurrentLang.ErrorTextTitle, client.Message, CurrentLang.OkButton);
815 // Debug.Log(client.Exception);
816 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
817 }
818 }
819 }
File name: VSCode.cs
Copy
480 static void CheckForUpdate()
481 {
482 var fileContent = string.Empty;
483
484 EditorUtility.DisplayProgressBar("VSCode", "Checking for updates ...", 0.5f);
485
486 // Because were not a runtime framework, lets just use the simplest way of doing this
487 try
488 {
489 using (var webClient = new System.Net.WebClient())
490 {
491 fileContent = webClient.DownloadString("https://raw.githubusercontent.com/dotBunny/VSCode/master/Plugins/Editor/VSCode.cs");
492 }
493 }
494 catch (Exception e)
495 {
496 if (Debug)
497 {
498 UnityEngine.Debug.Log("[VSCode] " + e.Message);
499
500 }
501
502 // Don't go any further if there is an error
503 return;
504 }
505 finally
506 {
507 EditorUtility.ClearProgressBar();
508 }
509
510 // Set the last update time
511 LastUpdate = DateTime.Now;
512
513 // Fix for oddity in downlo
514 if (fileContent.Substring(0, 2) != "/*")
515 {
516 int startPosition = fileContent.IndexOf("/*", StringComparison.CurrentCultureIgnoreCase);
517
518 // Jump over junk characters
519 fileContent = fileContent.Substring(startPosition);
520 }
521
522 string[] fileExploded = fileContent.Split('\n');
523 if (fileExploded.Length > 7)
524 {
525 float github = Version;
526 if (float.TryParse(fileExploded[6].Replace("*", "").Trim(), out github))
527 {
528 GitHubVersion = github;
529 }
530
531
532 if (github > Version)
533 {
534 var GUIDs = AssetDatabase.FindAssets("t:Script VSCode");
535 var path = Application.dataPath.Substring(0, Application.dataPath.Length - "/Assets".Length) + System.IO.Path.DirectorySeparatorChar +
536 AssetDatabase.GUIDToAssetPath(GUIDs[0]).Replace('/', System.IO.Path.DirectorySeparatorChar);
537
538 if (EditorUtility.DisplayDialog("VSCode Update", "A newer version of the VSCode plugin is available, would you like to update your version?", "Yes", "No"))
539 {
540 // Always make sure the file is writable
541 System.IO.FileInfo fileInfo = new System.IO.FileInfo(path);
542 fileInfo.IsReadOnly = false;
543
544 // Write update file
545 File.WriteAllText(path, fileContent);
546
547 // Force update on text file
548 AssetDatabase.ImportAsset(AssetDatabase.GUIDToAssetPath(GUIDs[0]), ImportAssetOptions.ForceUpdate);
549 }
550
551 }
552 }
553 }
File name: frmChangePassword.cs
Copy
23 private void Button1_Click(object sender, EventArgs e)
24 {
25 try
26 {
27 int RowsAffected = 0;
28 if ((txtUserName.Text.Trim().Length == 0))
29 {
30 MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
31 txtUserName.Focus();
32 return;
33 }
34 if ((txtOldPassword.Text.Trim().Length == 0))
35 {
36 MessageBox.Show("Please enter old password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
37 txtOldPassword.Focus();
38 return;
39 }
40 if ((txtNewPassword.Text.Trim().Length == 0))
41 {
42 MessageBox.Show("Please enter new password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
43 txtNewPassword.Focus();
44 return;
45 }
46 if ((txtConfirmPassword.Text.Trim().Length == 0))
47 {
48 MessageBox.Show("Please confirm new password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
49 txtConfirmPassword.Focus();
50 return;
51 }
52 if ((txtNewPassword.TextLength < 5))
53 {
54 MessageBox.Show("The New Password Should be of Atleast 5 Characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
55 txtNewPassword.Text = "";
56 txtConfirmPassword.Text = "";
57 txtNewPassword.Focus();
58 return;
59 }
60 else if ((txtNewPassword.Text != txtConfirmPassword.Text))
61 {
62 MessageBox.Show("Password do not match", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
63 txtNewPassword.Text = "";
64 txtOldPassword.Text = "";
65 txtConfirmPassword.Text = "";
66 txtOldPassword.Focus();
67 return;
68 }
69 else if ((txtOldPassword.Text == txtNewPassword.Text))
70 {
71 MessageBox.Show("Password is same..Re-enter new password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
72 txtNewPassword.Text = "";
73 txtConfirmPassword.Text = "";
74 txtNewPassword.Focus();
75 return;
76 }
77
78 con = new SqlConnection(cs.DBConn);
79 con.Open();
80 string co = "Update Registration set Password = '" + txtNewPassword.Text + "'where UserName='" + txtUserName.Text + "' and Password = '" + txtOldPassword.Text + "'";
81
82 cmd = new SqlCommand(co);
83 cmd.Connection = con;
84 RowsAffected = cmd.ExecuteNonQuery();
85 if ((RowsAffected > 0))
86 {
87 MessageBox.Show("Successfully changed", "Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
88 this.Hide();
89 txtUserName.Text = "";
90 txtNewPassword.Text = "";
91 txtOldPassword.Text = "";
92 txtConfirmPassword.Text = "";
93 frmLogin LoginForm1 = new frmLogin();
94 LoginForm1.Show();
95 LoginForm1.txtUserName.Text = "";
96 LoginForm1.txtPassword.Text = "";
97 LoginForm1.ProgressBar1.Visible = false;
98 LoginForm1.txtUserName.Focus();
99 }
100 else
101 {
102 MessageBox.Show("invalid user name or password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
103 txtUserName.Text = "";
104 txtNewPassword.Text = "";
105 txtOldPassword.Text = "";
106 txtConfirmPassword.Text = "";
107 txtUserName.Focus();
108 }
109 if ((con.State == ConnectionState.Open))
110 {
111 con.Close();
112 }
113 con.Close();
114 }
115 catch (Exception ex)
116 {
117 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
118 }
119 }
File name: frmChangePassword.cs
Copy
121 private void ChangePassword_FormClosing(object sender, FormClosingEventArgs e)
122 {
123 this.Hide();
124 frmLogin frm = new frmLogin();
125 frm.txtUserName.Text = "";
126 frm.txtPassword.Text = "";
127 frm.ProgressBar1.Visible = false;
128 frm.txtUserName.Focus();
129 frm.Show();
130 }
File name: frmCustomerMainMenu.cs
Copy
58 private void btnExit_Click(object sender, EventArgs e)
59 {
60 this.Hide();
61 frmCustomerProfileEntry o1 = new frmCustomerProfileEntry();
62 o1.Hide();
63 frmCustomerRegistration o2 = new frmCustomerRegistration();
64 o2.Hide();
65 frmUpdateCustomerDetails o3 = new frmUpdateCustomerDetails();
66 o3.Hide();
67 frmUpdateProfile o4 = new frmUpdateProfile();
68 o4.Hide();
69 frmCustomerOrders o5 = new frmCustomerOrders();
70 o5.Hide();
71 frmLogin frm = new frmLogin();
72 frm.txtUserName.Text = "";
73 frm.txtPassword.Text = "";
74 frm.ProgressBar1.Visible = false;
75 frm.txtUserName.Focus();
76 frm.Show();
77 }
File name: frmCustomerRegistration.cs
Copy
214 private void frmCustomerRegistration_FormClosing(object sender, FormClosingEventArgs e)
215 {
216 this.Hide();
217 frmLogin frm = new frmLogin();
218 frm.txtUserName.Text = "";
219 frm.txtPassword.Text = "";
220 frm.ProgressBar1.Visible = false;
221 frm.txtUserName.Focus();
222 frm.Show();
223 }
File name: frmLogin.cs
Copy
25 private void btnOK_Click(object sender, EventArgs e)
26 {
27 if (txtUserName.Text == "")
28 {
29 MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
30 txtUserName.Focus();
31 return;
32 }
33 if (txtPassword.Text == "")
34 {
35 MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
36 txtPassword.Focus();
37 return;
38 }
39 try
40 {
41 SqlConnection myConnection = default(SqlConnection);
42 myConnection = new SqlConnection(cs.DBConn);
43
44 SqlCommand myCommand = default(SqlCommand);
45
46 myCommand = new SqlCommand("SELECT Username,password FROM Registration WHERE Username = @username AND password = @UserPassword", myConnection);
47 SqlParameter uName = new SqlParameter("@username", SqlDbType.VarChar);
48 SqlParameter uPassword = new SqlParameter("@UserPassword", SqlDbType.VarChar);
49 uName.Value = txtUserName.Text;
50 uPassword.Value = txtPassword.Text;
51 myCommand.Parameters.Add(uName);
52 myCommand.Parameters.Add(uPassword);
53
54 myCommand.Connection.Open();
55
56 SqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
57
58 if (myReader.Read() == true)
59 {
60 int i;
61 ProgressBar1.Visible = true;
62 ProgressBar1.Maximum = 5000;
63 ProgressBar1.Minimum = 0;
64 ProgressBar1.Value = 4;
65 ProgressBar1.Step = 1;
66
67 for (i = 0; i <= 5000; i++)
68 {
69 ProgressBar1.PerformStep();
70 }
71 con = new SqlConnection(cs.DBConn);
72 con.Open();
73 string ct = "select usertype from Registration where Username='" + txtUserName.Text + "' and Password='" + txtPassword.Text + "'";
74 cmd = new SqlCommand(ct);
75 cmd.Connection = con;
76 rdr = cmd.ExecuteReader();
77 if (rdr.Read())
78 {
79 txtUserType.Text = (rdr.GetString(0));
80 }
81 if ((rdr != null))
82 {
83 rdr.Close();
84 }
85
86 if (txtUserType.Text.Trim()== "Admin")
87 {
88 this.Hide();
89
90 frm.masterEntryToolStripMenuItem.Enabled=true;
91 frm.usersToolStripMenuItem.Enabled=true;
92 frm.customerToolStripMenuItem1.Enabled=true;
93 frm.suppliersToolStripMenuItem.Enabled=true;
94 frm.productsToolStripMenuItem.Enabled=true;
95 frm.recordsToolStripMenuItem.Enabled=true;
96 frm.registrationToolStripMenuItem.Enabled=true;
97 frm.databaseToolStripMenuItem.Enabled=true;
98 frm.customerToolStripMenuItem.Enabled=true;
99 frm.supplierToolStripMenuItem.Enabled=true;
100 frm.productToolStripMenuItem.Enabled=true;
101 frm.stockToolStripMenuItem.Enabled=true;
102 frm.invoiceToolStripMenuItem.Enabled = true;
103 frm.Show();
104 frm.lblUser.Text = txtUserName.Text;
105 frm.lblUserType.Text = txtUserType.Text;
106 }
107 if (txtUserType.Text.Trim() == "Sales Person")
108 {
109 frm.masterEntryToolStripMenuItem.Enabled = false;
110 frm.usersToolStripMenuItem.Enabled = false;
111 frm.customerToolStripMenuItem1.Enabled = true;
112 frm.suppliersToolStripMenuItem.Enabled = false;
113 frm.productsToolStripMenuItem.Enabled = false;
114 frm.recordsToolStripMenuItem.Enabled = false;
115 frm.registrationToolStripMenuItem.Enabled = false;
116 frm.databaseToolStripMenuItem.Enabled = false;
117 frm.customerToolStripMenuItem.Enabled = true;
118 frm.supplierToolStripMenuItem.Enabled = false;
119 frm.productToolStripMenuItem.Enabled = false;
120 frm.stockToolStripMenuItem.Enabled = false;
121 frm.invoiceToolStripMenuItem.Enabled = true;
122 this.Hide();
123 frm.Show();
124 frm.lblUser.Text = txtUserName.Text;
125 frm.lblUserType.Text = txtUserType.Text;
126 }
127 if (txtUserType.Text.Trim() == "Warehouse Worker")
128 {
129 frm.masterEntryToolStripMenuItem.Enabled = false;
130 frm.usersToolStripMenuItem.Enabled = false;
131 frm.customerToolStripMenuItem1.Enabled = false;
132 frm.suppliersToolStripMenuItem.Enabled = false;
133 frm.productsToolStripMenuItem.Enabled = false;
134 frm.recordsToolStripMenuItem.Enabled = false;
135 frm.registrationToolStripMenuItem.Enabled = false;
136 frm.databaseToolStripMenuItem.Enabled = false;
137 frm.customerToolStripMenuItem.Enabled = false;
138 frm.supplierToolStripMenuItem.Enabled = false;
139 frm.productToolStripMenuItem.Enabled = false;
140 frm.stockToolStripMenuItem.Enabled = false;
141 frm.invoiceToolStripMenuItem.Enabled = false;
142 this.Hide();
143 frm.Show();
144 frm.lblUser.Text = txtUserName.Text;
145 frm.lblUserType.Text = txtUserType.Text;
146 }
147
148 if (txtUserType.Text.Trim() == "Warehouse Manager")
149 {
150 frm.masterEntryToolStripMenuItem.Enabled = false;
151 frm.usersToolStripMenuItem.Enabled = false;
152 frm.customerToolStripMenuItem1.Enabled = false;
153 frm.suppliersToolStripMenuItem.Enabled = false;
154 frm.productsToolStripMenuItem.Enabled = false;
155 frm.recordsToolStripMenuItem.Enabled = false;
156 frm.registrationToolStripMenuItem.Enabled = false;
157 frm.databaseToolStripMenuItem.Enabled = false;
158 frm.customerToolStripMenuItem.Enabled = false;
159 frm.supplierToolStripMenuItem.Enabled = true;
160 frm.productToolStripMenuItem.Enabled = true;
161 frm.stockToolStripMenuItem.Enabled = true;
162 frm.invoiceToolStripMenuItem.Enabled = false;
163 this.Hide();
164 frm.Show();
165 frm.lblUser.Text = txtUserName.Text;
166 frm.lblUserType.Text = txtUserType.Text;
167 }
168 if (txtUserType.Text.Trim() == "Customer")
169 {
170 frmCustomerMainMenu frm1 = new frmCustomerMainMenu();
171 this.Hide();
172 frm1.Show();
173 frm1.lblUser.Text = txtUserName.Text;
174 }
175 }
176 else
177 {
178 MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.Error);
179
180 txtUserName.Clear();
181 txtPassword.Clear();
182 txtUserName.Focus();
183
184 }
185 if (myConnection.State == ConnectionState.Open)
186 {
187 myConnection.Dispose();
188 }
189
190
191
192 }
193 catch (Exception ex)
194 {
195 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
196 }
197 }
File name: frmLogin.cs
Copy
199 private void Form1_Load(object sender, EventArgs e)
200 {
201 ProgressBar1.Visible = false;
202 txtUserName.Focus();
203 }
File name: frmMainMenu.cs
Copy
105 private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
106 {
107 this.Hide();
108 frmCategory o1 = new frmCategory();
109 o1.Hide();
110 frmSubCategory o2 = new frmSubCategory();
111 o2.Hide();
112 frmProduct o3 = new frmProduct();
113 o3.Hide();
114 frmRegisteredUsersDetails o4 = new frmRegisteredUsersDetails();
115 o4.Hide();
116 frmRegistration o5 = new frmRegistration();
117 o5.Hide();
118 frmStockRecord o6 = new frmStockRecord();
119 o6.Hide();
120 frmCustomersRecord o7 = new frmCustomersRecord();
121 o7.Hide();
122 frmSuppliersRecord o8 = new frmSuppliersRecord();
123 o8.Hide();
124 frmProductsRecord2 o9 = new frmProductsRecord2();
125 o9.Hide();
126 frmSalesRecord2 o10 = new frmSalesRecord2();
127 o10.Hide();
128 frmLogin frm = new frmLogin();
129 frm.Show();
130 frm.txtUserName.Text = "";
131 frm.txtPassword.Text = "";
132 frm.ProgressBar1.Visible = false;
133 frm.txtUserName.Focus();
134 }
ProgressBar 121 lượt xem
Gõ tìm kiếm nhanh...