Top
How do I use Top
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: frmThi.cs
Copy
225 private void timer1_Tick(object sender, EventArgs e)
226 {
227 p--;
228 lbtime.Text =p.ToString() +" phut";
229 if (p==0)
230 {
231 timer1.Stop();
232 MessageBox.Show("Da het gio lam bai");
233 }
234 }
File name: frmThiThat.cs
Copy
261 private void btketthuc_Click(object sender, EventArgs e)
262 {
263 if (MessageBox.Show("Bạn có chắc chắn kết thúc không ?" , "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
264 {
265 this.Hide();
266 try
267 {
268 timer1.Stop();
269 btketthuc.Enabled = false;
270
271 GhiLaiDapAnTS();
272 SoCauDung = 0;
273 for (int i = 0; i < SoCauHoi; i++)
274 {
275 if (BangDeThi.Rows[i][6].ToString().ToUpper() == BangDeThi.Rows[i][7].ToString().ToUpper())
276 SoCauDung++;
277
278 }
279
280 diem = SoCauDung * 2;
281 MessageBox.Show("Đúng " + SoCauDung.ToString() + " câu " + " Bạn được " + diem.ToString() + " điểm ");
282 this.Close();
283 string ten = lbhoten.Text;
284 string mats = lbmathisinh.Text;
285 string diem1 = diem.ToString();
286 string socaudung = SoCauDung.ToString();
287 frmKetQua ketqua = new frmKetQua(ten,mats,diem1,socaudung);
288 ketqua.ShowDialog();
289 //them form ket qua tai day
290
291 }
292 catch (Exception ex)
293 { MessageBox.Show(ex.Message); }
294 }
295 else
296 { return; }
297 }
File name: frmThiThat.cs
Copy
301 private void timer1_Tick_1(object sender, EventArgs e)
302 {
303 timer1.Interval = 1000;
304
305 s--;
306 th--;
307 if (th == 0)
308 {
309 timer1.Stop();
310 MessageBox.Show("Hết giờ làm bài!", "Thong bao");
311 checkBox1.Checked = false;
312 checkBox2.Checked = false;
313 checkBox3.Checked = false;
314 checkBox4.Checked = false;
315
316 GhiLaiDapAnTS();
317 SoCauDung = 0;
318 for (int i = 0; i < SoCauHoi; i++)
319 {
320 if (BangDeThi.Rows[i][6].ToString().ToUpper() == BangDeThi.Rows[i][7].ToString().ToUpper())
321 SoCauDung++;
322 }
323 int diem;
324 diem = SoCauDung * 2;
325 MessageBox.Show("Đúng " + SoCauDung.ToString()+" câu " + " Bạn được " + diem.ToString() + " điểm ");
326 this.Close();
327
328 }
329 if (s == 0)
330 {
331 p--;
332 if (p == 0)
333 {
334 s = 60;
335 th = s;
336 }
337 s = 60;
338 }
339
340 lblHour.Text = h.ToString() + " : " + p.ToString() + " : " + s.ToString();
341
342 }
File name: NamePickGui.cs
Copy
38 public void OnGUI()
39 {
40 // Enter-Key handling:
41 if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
42 {
43 if (!string.IsNullOrEmpty(this.InputLine))
44 {
45 this.StartChat();
46 return;
47 }
48 }
49
50
51 GUI.skin.label.wordWrap = true;
52 GUILayout.BeginArea(guiCenteredRect);
53
54
55 if (this.chatComponent != null && string.IsNullOrEmpty(this.chatComponent.ChatAppId))
56 {
57 GUILayout.Label("To continue, configure your Chat AppId.\nIt's listed in the Chat Dashboard (online).\nStop play-mode and edit:\nScripts/ChatGUI in the Hierarchy.");
58 if (GUILayout.Button("Open Chat Dashboard"))
59 {
60 Application.OpenURL("https://www.exitgames.com/en/Chat/Dashboard");
61 }
62 GUILayout.EndArea();
63 return;
64 }
65
66 GUILayout.Label(this.helpText);
67
68 GUILayout.BeginHorizontal();
69 GUI.SetNextControlName("NameInput");
70 this.InputLine = GUILayout.TextField(this.InputLine);
71 if (GUILayout.Button("Connect", GUILayout.ExpandWidth(false)))
72 {
73 this.StartChat();
74 }
75 GUILayout.EndHorizontal();
76
77 GUILayout.EndArea();
78
79
80 GUI.FocusControl("NameInput");
81 }
File name: PickupCamera.cs
Copy
198 void SetUpRotation( Vector3 centerPos, Vector3 headPos )
199 {
200 // Now it's getting hairy. The devil is in the details here, the big issue is jumping of course.
201 // * When jumping up and down we don't want to center the guy in screen space.
202 // This is important to give a feel for how high you jump and avoiding large camera movements.
203 //
204 // * At the same time we dont want him to ever go out of screen and we want all rotations to be totally smooth.
205 //
206 // So here is what we will do:
207 //
208 // 1. We first find the rotation around the y axis. Thus he is always centered on the y-axis
209 // 2. When grounded we make him be centered
210 // 3. When jumping we keep the camera rotation but rotate the camera to get him back into view if his head is above some threshold
211 // 4. When landing we smoothly interpolate towards centering him on screen
212 Vector3 cameraPos = cameraTransform.position;
213 Vector3 offsetToCenter = centerPos - cameraPos;
214
215 // Generate base rotation only around y-axis
216 Quaternion yRotation = Quaternion.LookRotation( new Vector3( offsetToCenter.x, 0, offsetToCenter.z ) );
217
218 Vector3 relativeOffset = Vector3.forward * distance + Vector3.down * height;
219 cameraTransform.rotation = yRotation * Quaternion.LookRotation( relativeOffset );
220
221 // Calculate the projected center position and top position in world space
222 Ray centerRay = m_CameraTransformCamera.ViewportPointToRay( new Vector3( 0.5f, 0.5f, 1 ) );
223 Ray topRay = m_CameraTransformCamera.ViewportPointToRay( new Vector3( 0.5f, clampHeadPositionScreenSpace, 1 ) );
224
225 Vector3 centerRayPos = centerRay.GetPoint( distance );
226 Vector3 topRayPos = topRay.GetPoint( distance );
227
228 float centerToTopAngle = Vector3.Angle( centerRay.direction, topRay.direction );
229
230 float heightToAngle = centerToTopAngle / ( centerRayPos.y - topRayPos.y );
231
232 float extraLookAngle = heightToAngle * ( centerRayPos.y - centerPos.y );
233 if( extraLookAngle < centerToTopAngle )
234 {
235 extraLookAngle = 0;
236 }
237 else
238 {
239 extraLookAngle = extraLookAngle - centerToTopAngle;
240 cameraTransform.rotation *= Quaternion.Euler( -extraLookAngle, 0, 0 );
241 }
242 }
File name: ThirdPersonCamera.cs
Copy
190 void SetUpRotation( Vector3 centerPos, Vector3 headPos )
191 {
192 // Now it's getting hairy. The devil is in the details here, the big issue is jumping of course.
193 // * When jumping up and down we don't want to center the guy in screen space.
194 // This is important to give a feel for how high you jump and avoiding large camera movements.
195 //
196 // * At the same time we dont want him to ever go out of screen and we want all rotations to be totally smooth.
197 //
198 // So here is what we will do:
199 //
200 // 1. We first find the rotation around the y axis. Thus he is always centered on the y-axis
201 // 2. When grounded we make him be centered
202 // 3. When jumping we keep the camera rotation but rotate the camera to get him back into view if his head is above some threshold
203 // 4. When landing we smoothly interpolate towards centering him on screen
204 Vector3 cameraPos = cameraTransform.position;
205 Vector3 offsetToCenter = centerPos - cameraPos;
206
207 // Generate base rotation only around y-axis
208 Quaternion yRotation = Quaternion.LookRotation( new Vector3( offsetToCenter.x, 0, offsetToCenter.z ) );
209
210 Vector3 relativeOffset = Vector3.forward * distance + Vector3.down * height;
211 cameraTransform.rotation = yRotation * Quaternion.LookRotation( relativeOffset );
212
213 // Calculate the projected center position and top position in world space
214 Ray centerRay = m_CameraTransformCamera.ViewportPointToRay( new Vector3( 0.5f, 0.5f, 1 ) );
215 Ray topRay = m_CameraTransformCamera.ViewportPointToRay( new Vector3( 0.5f, clampHeadPositionScreenSpace, 1 ) );
216
217 Vector3 centerRayPos = centerRay.GetPoint( distance );
218 Vector3 topRayPos = topRay.GetPoint( distance );
219
220 float centerToTopAngle = Vector3.Angle( centerRay.direction, topRay.direction );
221
222 float heightToAngle = centerToTopAngle / ( centerRayPos.y - topRayPos.y );
223
224 float extraLookAngle = heightToAngle * ( centerRayPos.y - centerPos.y );
225 if( extraLookAngle < centerToTopAngle )
226 {
227 extraLookAngle = 0;
228 }
229 else
230 {
231 extraLookAngle = extraLookAngle - centerToTopAngle;
232 cameraTransform.rotation *= Quaternion.Euler( -extraLookAngle, 0, 0 );
233 }
234 }
File name: WorkerInGame.cs
Copy
89 public void OnFailedToConnectToPhoton()
90 {
91 Debug.Log("OnFailedToConnectToPhoton");
92
93 // back to main menu
94 Application.LoadLevel(WorkerMenu.SceneNameMenu);
95 }
File name: WorkerMenu.cs
Copy
234 public void OnFailedToConnectToPhoton(object parameters)
235 {
236 this.connectFailed = true;
237 Debug.Log("OnFailedToConnectToPhoton. StatusCode: " + parameters + " ServerAddress: " + PhotonNetwork.networkingPeer.ServerAddress);
238 }
File name: PhotonConverter.cs
Copy
160 static void ConvertScripts(List161 {
162 bool ignoreWarningIsLogged = false;
163
164 foreach (string script in scriptPathList)
165 {
166 if (script.Contains("PhotonNetwork")) //Don't convert this file (and others)
167 {
168 if (!ignoreWarningIsLogged)
169 {
170 ignoreWarningIsLogged = true;
171 Debug.LogWarning("Conversion to PUN ignores all files with \"PhotonNetwork\" in their file-path.\nCheck: " + script);
172 }
173 continue;
174 }
175 if (script.Contains("Image Effects"))
176 {
177 continue;
178 }
179
180 ConvertToPhotonAPI(script);
181 }
182
183 foreach (string script in scriptPathList)
184 {
185 AssetDatabase.ImportAsset(script, ImportAssetOptions.ForceUpdate);
186 }
187 }
File name: PhotonConverter.cs
Copy
189 static void ConvertToPhotonAPI(string file)
190 {
191 string text = File.ReadAllText(file);
192
193 bool isJS = file.Contains(".js");
194
195 file = file.Replace("\\", "/"); // Get Class name for JS
196 string className = file.Substring(file.LastIndexOf("/")+1);
197 className = className.Substring(0, className.IndexOf("."));
198
199
200 //REGEXP STUFF
201 //Valid are: Space { } , /n /r
202 //string NOT_VAR = @"([^A-Za-z0-9_\[\]\.]+)";
203 string NOT_VAR_WITH_DOT = @"([^A-Za-z0-9_]+)";
204
205 //string VAR_NONARRAY = @"[^A-Za-z0-9_]";
206
207
208 //NetworkView
209 {
210 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkView" + NOT_VAR_WITH_DOT, "$1PhotonView$2");
211 text = PregReplace(text, NOT_VAR_WITH_DOT + "networkView" + NOT_VAR_WITH_DOT, "$1photonView$2");
212 text = PregReplace(text, NOT_VAR_WITH_DOT + "stateSynchronization" + NOT_VAR_WITH_DOT, "$1synchronization$2");
213 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkStateSynchronization" + NOT_VAR_WITH_DOT, "$1ViewSynchronization$2"); // map Unity enum to ours
214 //.RPC
215 text = PregReplace(text, NOT_VAR_WITH_DOT + "RPCMode.Server" + NOT_VAR_WITH_DOT, "$1PhotonTargets.MasterClient$2");
216 text = PregReplace(text, NOT_VAR_WITH_DOT + "RPCMode" + NOT_VAR_WITH_DOT, "$1PhotonTargets$2");
217 }
218
219 //NetworkMessageInfo: 100%
220 {
221 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkMessageInfo" + NOT_VAR_WITH_DOT, "$1PhotonMessageInfo$2");
222 text = PregReplace(text, NOT_VAR_WITH_DOT + "networkView" + NOT_VAR_WITH_DOT, "$1photonView$2");
223 }
224
225 //NetworkViewID:
226 {
227 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkViewID" + NOT_VAR_WITH_DOT, "$1int$2"); //We simply use an int
228 }
229
230 //NetworkPlayer
231 {
232 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkPlayer" + NOT_VAR_WITH_DOT, "$1PhotonPlayer$2");
233 }
234
235 //Network
236 {
237 //Monobehaviour callbacks
238 {
239 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnPlayerConnected" + NOT_VAR_WITH_DOT, "$1OnPhotonPlayerConnected$2");
240 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnPlayerDisconnected" + NOT_VAR_WITH_DOT, "$1OnPhotonPlayerDisconnected$2");
241 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnNetworkInstantiate" + NOT_VAR_WITH_DOT, "$1OnPhotonInstantiate$2");
242 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnSerializeNetworkView" + NOT_VAR_WITH_DOT, "$1OnPhotonSerializeView$2");
243 text = PregReplace(text, NOT_VAR_WITH_DOT + "BitStream" + NOT_VAR_WITH_DOT, "$1PhotonStream$2");
244
245 //Not completely the same meaning
246 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnServerInitialized" + NOT_VAR_WITH_DOT, "$1OnCreatedRoom$2");
247 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnConnectedToServer" + NOT_VAR_WITH_DOT, "$1OnJoinedRoom$2");
248
249 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnFailedToConnectToMasterServer" + NOT_VAR_WITH_DOT, "$1OnFailedToConnectToPhoton$2");
250 text = PregReplace(text, NOT_VAR_WITH_DOT + "OnFailedToConnect" + NOT_VAR_WITH_DOT, "$1OnFailedToConnect_OBSELETE$2");
251 }
252
253 //Variables
254 {
255
256 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.connections" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.playerList$2");
257 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.isServer" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isMasterClient$2");
258 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.isClient" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isNonMasterClientInRoom$2");
259
260 text = PregReplace(text, NOT_VAR_WITH_DOT + "NetworkPeerType" + NOT_VAR_WITH_DOT, "$1ConnectionState$2");
261 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.peerType" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.connectionState$2");
262 text = PregReplace(text, NOT_VAR_WITH_DOT + "ConnectionState.Server" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isMasterClient$2");
263 text = PregReplace(text, NOT_VAR_WITH_DOT + "ConnectionState.Client" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.isNonMasterClientInRoom$2");
264 text = PregReplace(text, NOT_VAR_WITH_DOT + "PhotonNetwork.playerList.Length" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.playerList.Count$2");
265
266 /*DROPPED:
267 minimumAllocatableViewIDs
268 natFacilitatorIP is dropped
269 natFacilitatorPort is dropped
270 connectionTesterIP
271 connectionTesterPort
272 proxyIP
273 proxyPort
274 useProxy
275 proxyPassword
276 */
277 }
278
279 //Methods
280 {
281 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.InitializeServer" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.CreateRoom$2");
282 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.Connect" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.JoinRoom$2");
283 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.GetAveragePing" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.GetPing$2");
284 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network.GetLastPing" + NOT_VAR_WITH_DOT, "$1PhotonNetwork.GetPing$2");
285 /*DROPPED:
286 TestConnection
287 TestConnectionNAT
288 HavePublicAddress
289 */
290 }
291
292 //Overall
293 text = PregReplace(text, NOT_VAR_WITH_DOT + "Network" + NOT_VAR_WITH_DOT, "$1PhotonNetwork$2");
294
295
296 //Changed methods
297 string ignoreMe = @"([A-Za-z0-9_\[\]\(\) ]+)";
298
299 text = PregReplace(text, NOT_VAR_WITH_DOT + "PhotonNetwork.GetPing\\(" + ignoreMe+"\\);", "$1PhotonNetwork.GetPing();");
300 text = PregReplace(text, NOT_VAR_WITH_DOT + "PhotonNetwork.CloseConnection\\(" + ignoreMe+","+ignoreMe+"\\);", "$1PhotonNetwork.CloseConnection($2);");
301
302 }
303
304 //General
305 {
306 if (text.Contains("Photon")) //Only use the PhotonMonoBehaviour if we use photonView and friends.
307 {
308 if (isJS)//JS
309 {
310 if (text.Contains("extends MonoBehaviour"))
311 text = PregReplace(text, "extends MonoBehaviour", "extends Photon.MonoBehaviour");
312 else
313 text = "class " + className + " extends Photon.MonoBehaviour {\n" + text + "\n}";
314 }
315 else //C#
316 text = PregReplace(text, ": MonoBehaviour", ": Photon.MonoBehaviour");
317 }
318 }
319
320 File.WriteAllText(file, text);
321 }
Download file with original file name:Top
Top 147 lượt xem
Gõ tìm kiếm nhanh...