TWO
How do I use T W O
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: FormXemDiem.cs
Copy
85 private void btnXuatRaExcel_Click(object sender, EventArgs e)
86 {
87 try
88 {
89
90 Excel.Application objExcelApp = new Excel.Application();
91 Excel.Workbook objExcelWorkbook = objExcelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
92 Excel.Worksheet objSheet = (Excel.Worksheet)objExcelWorkbook.Worksheets[1];
93 //objSheet.Cells.Interior.Color.ToString() = 'blue';
94 objSheet = (Excel.Worksheet)objExcelWorkbook.Sheets[1];
95 objSheet.Cells.HorizontalAlignment = Excel.Constants.xlCenter;
96 objSheet.Cells[2, 5] = "BẢNG ĐIỂM CỦA SINH VIÊN";
97 objSheet.Cells[5, 3] = "Mã Học Phần";
98 objSheet.Cells[5, 4] = "Mã Nhóm Học Phần";
99 objSheet.Cells[5, 5] = "Tên Học Phần";
100 objSheet.Cells[5, 6] = "Điểm Thi";
101 objSheet.Cells[5, 7] = "Điểm Quá Trình";
102 objSheet.Cells[5, 8] = "Điểm Xếp Loại";
103 objSheet.Cells[3, 3] = "Mã Học Kỳ : "+cmbMaHK.SelectedValue.ToString()+"";
104 objSheet.Cells[4, 3] = "Mã SV : " + txtMaSV.Text + "";
105 objSheet.Cells[9,10] = "ĐIỂM TỔNG KẾT";
106 objSheet.Cells[10,10] = "Hệ 10 : "+txtHe10.Text+"";
107 objSheet.Cells[11,10] = "Hệ 4 : "+txtHe4.Text+"";
108 for (int i = 0; i < dgvKetQua.Rows.Count ; i++)
109 {
110 for (int j = 0; j < dgvKetQua.Columns.GetColumnCount(DataGridViewElementStates.Displayed); j++)
111 {
112 objSheet.Cells[i + 6, j + 3] = dgvKetQua.Rows[i].Cells[j].Value.ToString();
113 objSheet.Columns.AutoFit();
114 }
115 }
116 objExcelApp.Visible = true;
117 }
118 catch (Exception ex)
119 {
120 MessageBox.Show(ex.Message);
121 }
122 }
File name: FormXemDiemLop.cs
Copy
77 private void btnXuatRaExcel_Click(object sender, EventArgs e)
78 {
79 try
80 {
81
82 Excel.Application objExcelApp = new Excel.Application();
83 Excel.Workbook objExcelWorkbook = objExcelApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
84 Excel.Worksheet objSheet = (Excel.Worksheet)objExcelWorkbook.Worksheets[1];
85 //objSheet.Cells.Interior.Color.ToString() = 'blue';
86 objSheet = (Excel.Worksheet)objExcelWorkbook.Sheets[1];
87 objSheet.Cells.HorizontalAlignment = Excel.Constants.xlCenter;
88 objSheet.Cells[2, 5] = "BẢNG ĐIỂM CỦA LỚP";
89 objSheet.Cells[3, 3] = "Mã Học Kỳ : "+cmbMaHK.SelectedValue.ToString()+"";
90 objSheet.Cells[4, 3] = "Mã Lớp : " + cmbMaLop.SelectedValue.ToString() + "";
91 objSheet.Cells[5, 4] = "Mã Sinh Viên";
92 objSheet.Cells[5, 5] = "Tên Sinh Viên";
93 objSheet.Cells[5, 6] = "Điểm Trung Bình";
94 //select sv.MaSV,TenSV,TrungBinhCuoiKyHe10
95
96 for (int i = 0; i < dgvKetQua.Rows.Count ; i++)
97 {
98 for (int j = 0; j < dgvKetQua.Columns.GetColumnCount(DataGridViewElementStates.Displayed); j++)
99 {
100 objSheet.Cells[i + 6, j + 4] = dgvKetQua.Rows[i].Cells[j].Value.ToString();
101 objSheet.Columns.AutoFit();
102 }
103 }
104 objExcelApp.Visible = true;
105 }
106 catch (Exception ex)
107 {
108 MessageBox.Show(ex.Message);
109 }
110 }
File name: Demo2DJumpAndRun.cs
Copy
6 void OnJoinedRoom()
7 {
8 if( PhotonNetwork.isMasterClient == false )
9 {
10 return;
11 }
12
13 PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 5.5f, 0 ), Quaternion.identity, 0, null );
14 PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 4.5f, 0 ), Quaternion.identity, 0, null );
15 PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( -4.5f, 3.5f, 0 ), Quaternion.identity, 0, null );
16
17 PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 5.5f, 0 ), Quaternion.identity, 0, null );
18 PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 4.5f, 0 ), Quaternion.identity, 0, null );
19 PhotonNetwork.InstantiateSceneObject( "Physics Box", new Vector3( 4.5f, 3.5f, 0 ), Quaternion.identity, 0, null );
20 }
File name: DemoBoxesGui.cs
Copy
8 void OnGUI()
9 {
10 if (HideUI)
11 {
12 return;
13 }
14
15 GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
16
17 if (!PhotonNetwork.connected)
18 {
19 if (GUILayout.Button("Connect"))
20 {
21 PhotonNetwork.ConnectUsingSettings(null);
22 }
23 }
24 else
25 {
26 if (GUILayout.Button("Disconnect"))
27 {
28 PhotonNetwork.Disconnect();
29 }
30 }
31
32 }
File name: DemoOwnershipGui.cs
Copy
23 public void OnGUI()
24 {
25 GUI.skin = this.Skin;
26 GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
27 {
28 string label = TransferOwnershipOnRequest ? "passing objects" : "rejecting to pass";
29 if (GUILayout.Button(label))
30 {
31 this.TransferOwnershipOnRequest = !this.TransferOwnershipOnRequest;
32 }
33 }
34 GUILayout.EndArea();
35
36
37
38 if (PhotonNetwork.inRoom)
39 {
40 int playerNr = PhotonNetwork.player.ID;
41 string playerIsMaster = PhotonNetwork.player.isMasterClient ? "(master) " : "";
42 string playerColor = PlayerVariables.GetColorName(PhotonNetwork.player.ID);
43 GUILayout.Label(string.Format("player {0}, {1} {2}(you)", playerNr, playerColor, playerIsMaster));
44
45 foreach (PhotonPlayer otherPlayer in PhotonNetwork.otherPlayers)
46 {
47 playerNr = otherPlayer.ID;
48 playerIsMaster = otherPlayer.isMasterClient ? "(master)" : "";
49 playerColor = PlayerVariables.GetColorName(otherPlayer.ID);
50 GUILayout.Label(string.Format("player {0}, {1} {2}", playerNr, playerColor, playerIsMaster));
51 }
52
53 if (PhotonNetwork.inRoom && PhotonNetwork.otherPlayers.Length == 0)
54 {
55 GUILayout.Label("Join more clients to switch object-control.");
56 }
57 }
58 else
59 {
60 GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
61 }
62 }
File name: InstantiateCube.cs
Copy
12 void OnClick()
13 {
14 if (PhotonNetwork.connectionStateDetailed != PeerState.Joined)
15 {
16 // only use PhotonNetwork.Instantiate while in a room.
17 return;
18 }
19
20 switch (InstantiateType)
21 {
22 case 0:
23 PhotonNetwork.Instantiate(Prefab.name, this.transform.position + 3*Vector3.up, Quaternion.identity, 0);
24 break;
25 case 1:
26 PhotonNetwork.InstantiateSceneObject(Prefab.name, InputToEvent.inputHitPos + new Vector3(0, 5f, 0), Quaternion.identity, 0, null);
27 break;
28 }
29 }
File name: OnClickRequestOwnership.cs
Copy
8 public void OnClick()
9 {
10 if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
11 {
12 Vector3 colVector = new Vector3( Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ) );
13 this.photonView.RPC( "ColorRpc", PhotonTargets.AllBufferedViaServer, colVector );
14 }
15 else
16 {
17 if( this.photonView.ownerId == PhotonNetwork.player.ID )
18 {
19 Debug.Log( "Not requesting ownership. Already mine." );
20 return;
21 }
22
23 this.photonView.RequestOwnership();
24 }
25 }
File name: OnClickRightDestroy.cs
Copy
5 public void OnPressRight()
6 {
7 Debug.Log("RightClick Destroy");
8 PhotonNetwork.Destroy(gameObject);
9 }
File name: OnJoinInstantiate.cs
Copy
13 public void OnJoinedRoom()
14 {
15 Vector3 pos = Vector3.zero;
16 pos.x += PhotonNetwork.player.ID;
17
18 if (!InstantiateSceneObjects)
19 {
20
21 newObj = PhotonNetwork.Instantiate(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
22
23
24 // anything you do with newObj locally is not reflected on the other clients.
25 // you can add a script to the Prefab to do some instantiation in Awake() and you can call RPCs on newObj now.
26 }
27 else
28 {
29 newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
30 //PhotonView pv = newObj.GetComponent
31 //Debug.Log(pv.ownerId + " " + pv.viewID);
32 }
33 }
File name: GUICustomAuth.cs
Copy
70 public void ConnectWithNickname()
71 {
72 RootOf3dButtons.SetActive(false);
73
74 PhotonNetwork.AuthValues = null; // null by default but maybe set in a previous session.
75 PhotonNetwork.ConnectUsingSettings("1.0");
76
77 // PhotonNetwork.playerName gets set in GUIFriendFinding
78 // a UserID is not used in this case (no AuthValues set)
79 }
Download file with original file name:TWO
TWO 123 lượt xem
Gõ tìm kiếm nhanh...