Main
How do I use Main
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: Program.cs
Copy
14 static void Main()
15 {
16 Application.EnableVisualStyles();
17 Application.SetCompatibleTextRenderingDefault(false);
18 Application.Run(new Form9());
19 }
File name: frmLogin.cs
Copy
40 private void đăngXuấtToolStripMenuItem_Click(object sender, EventArgs e)
41 {
42 frmLogin fMain = new frmLogin();
43 fMain.Show();
44 fMain.Close();
45 }
File name: frmMain.cs
Copy
19 private void frmMain_Load(object sender, EventArgs e)
20 {
21 tship.Text = "Ngày "+DateTime.Now.Day.ToString() + " Tháng " + DateTime.Now.Month.ToString() + " Năm " + DateTime.Now.Year.ToString();
22 tship2.Text = tship2.Text.Substring(tship2.Text.Length - 1, 1) + tship2.Text.Substring(0, tship2.Text.Length - 1);
23
24 //frmLogin fLog = new frmLogin();
25 //fLog.MdiParent = this;
26 //fLog.Show();
27 //this.WindowState = FormWindowState.Normal;
28 }
File name: Program.cs
Copy
14 static void Main()
15 {
16 Application.EnableVisualStyles();
17 Application.SetCompatibleTextRenderingDefault(false);
18 Application.Run(new frmMain());
19 }
File name: ClickAndDrag.cs
Copy
11 void Update ()
12 {
13 if (!photonView.isMine)
14 {
15 return;
16 }
17
18 InputToEvent input = Camera.main.GetComponent
19 if (input == null) return;
20 if (!following)
21 {
22 if (input.Dragging)
23 {
24 camOnPress = this.transform.position;
25 following = true;
26 }
27 else
28 {
29 return;
30 }
31 }
32 else
33 {
34 if (input.Dragging)
35 {
36 Vector3 target = camOnPress - (new Vector3(input.DragVector.x, 0, input.DragVector.y) * factor);
37 this.transform.position = Vector3.Lerp(this.transform.position, target, Time.deltaTime*.5f);
38 }
39 else
40 {
41 camOnPress = Vector3.zero;
42 following = false;
43 }
44 }
45 }
File name: PunStartup.cs
Copy
68 public static void LoadPunDemoHub()
69 {
70 bool ret = EditorApplication.OpenScene(demoBasePath + demoPaths[0]);
71 if (ret)
72 {
73 Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(demoBasePath + demoPaths[0]);
74 }
75 }
File name: PickupCamera.cs
Copy
41 void OnEnable()
42 {
43 if( this.photonView != null && !this.photonView.isMine )
44 {
45 this.enabled = false;
46 return;
47 }
48
49 if( !cameraTransform && Camera.main )
50 cameraTransform = Camera.main.transform;
51 if( !cameraTransform )
52 {
53 Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
54 enabled = false;
55 }
56
57 m_CameraTransformCamera = cameraTransform.GetComponent
58
59
60 _target = transform;
61 if( _target )
62 {
63 controller = _target.GetComponent
64 }
65
66 if( controller )
67 {
68 CharacterController characterController = (CharacterController)_target.GetComponent
69 centerOffset = characterController.bounds.center - _target.position;
70 headOffset = centerOffset;
71 headOffset.y = characterController.bounds.max.y - _target.position.y;
72 }
73 else
74 Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
75
76
77 Cut( _target, centerOffset );
78 }
File name: PickupController.cs
Copy
308 void UpdateSmoothedMovementDirection()
309 {
310 Transform cameraTransform = Camera.main.transform;
311 bool grounded = IsGrounded();
312
313 // Forward vector relative to the camera along the x-z plane
314 Vector3 forward = cameraTransform.TransformDirection(Vector3.forward);
315 forward.y = 0;
316 forward = forward.normalized;
317
318 // Right vector relative to the camera
319 // Always orthogonal to the forward vector
320 Vector3 right = new Vector3(forward.z, 0, -forward.x);
321
322 float v = Input.GetAxisRaw("Vertical");
323 float h = Input.GetAxisRaw("Horizontal");
324
325 // Are we moving backwards or looking backwards
326 if (v < -0.2f)
327 movingBack = true;
328 else
329 movingBack = false;
330
331 bool wasMoving = isMoving;
332 isMoving = Mathf.Abs(h) > 0.1f || Mathf.Abs(v) > 0.1f;
333
334 // Target direction relative to the camera
335 Vector3 targetDirection = h * right + v * forward;
336 // Debug.Log("targetDirection " + targetDirection);
337
338 // Grounded controls
339 if (grounded)
340 {
341 // Lock camera for short period when transitioning moving & standing still
342 lockCameraTimer += Time.deltaTime;
343 if (isMoving != wasMoving)
344 lockCameraTimer = 0.0f;
345
346 // We store speed and direction seperately,
347 // so that when the character stands still we still have a valid forward direction
348 // moveDirection is always normalized, and we only update it if there is user input.
349 if (targetDirection != Vector3.zero)
350 {
351 // If we are really slow, just snap to the target direction
352 if (moveSpeed < walkSpeed * 0.9f && grounded)
353 {
354 moveDirection = targetDirection.normalized;
355 }
356 // Otherwise smoothly turn towards it
357 else
358 {
359 moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
360
361 moveDirection = moveDirection.normalized;
362 }
363 }
364
365 // Smooth the speed based on the current target direction
366 float curSmooth = speedSmoothing * Time.deltaTime;
367
368 // Choose target speed
369 //* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways
370 float targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0f);
371
372 _characterState = PickupCharacterState.Idle;
373
374 // Pick speed modifier
375 if ((Input.GetKey(KeyCode.LeftShift) | Input.GetKey(KeyCode.RightShift)) && isMoving)
376 {
377 targetSpeed *= runSpeed;
378 _characterState = PickupCharacterState.Running;
379 }
380 else if (Time.time - trotAfterSeconds > walkTimeStart)
381 {
382 targetSpeed *= trotSpeed;
383 _characterState = PickupCharacterState.Trotting;
384 }
385 else if (isMoving)
386 {
387 targetSpeed *= walkSpeed;
388 _characterState = PickupCharacterState.Walking;
389 }
390
391 moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
392
393 // Reset walk time start when we slow down
394 if (moveSpeed < walkSpeed * 0.3f)
395 walkTimeStart = Time.time;
396 }
397 // In air controls
398 else
399 {
400 // Lock camera while in air
401 if (jumping)
402 lockCameraTimer = 0.0f;
403
404 if (isMoving)
405 inAirVelocity += targetDirection.normalized * Time.deltaTime * inAirControlAcceleration;
406 }
407 }
File name: ThirdPersonCamera.cs
Copy
40 void OnEnable()
41 {
42 if( !cameraTransform && Camera.main )
43 cameraTransform = Camera.main.transform;
44 if( !cameraTransform )
45 {
46 Debug.Log( "Please assign a camera to the ThirdPersonCamera script." );
47 enabled = false;
48 }
49
50 m_CameraTransformCamera = cameraTransform.GetComponent
51
52 _target = transform;
53 if( _target )
54 {
55 controller = _target.GetComponent
56 }
57
58 if( controller )
59 {
60 CharacterController characterController = (CharacterController)_target.GetComponent
61 centerOffset = characterController.bounds.center - _target.position;
62 headOffset = centerOffset;
63 headOffset.y = characterController.bounds.max.y - _target.position.y;
64 }
65 else
66 Debug.Log( "Please assign a target to the camera that has a ThirdPersonController script attached." );
67
68
69 Cut( _target, centerOffset );
70 }
Download file with original file name:Main
Main 204 lượt xem
Gõ tìm kiếm nhanh...