Collection
How do I use Collection
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonEditor.cs
Copy
975 public static System.Type[] GetAllSubTypesInScripts(System.Type aBaseClass)
976 {
977 var result = new System.Collections.Generic.List
978 System.Reflection.Assembly[] AS = System.AppDomain.CurrentDomain.GetAssemblies();
979 foreach (var A in AS)
980 {
981 // this skips all but the Unity-scripted assemblies for RPC-list creation. You could remove this to search all assemblies in project
982 if (!A.FullName.StartsWith("Assembly-"))
983 {
984 // Debug.Log("Skipping Assembly: " + A);
985 continue;
986 }
987
988 //Debug.Log("Assembly: " + A.FullName);
989 System.Type[] types = A.GetTypes();
990 foreach (var T in types)
991 {
992 if (T.IsSubclassOf(aBaseClass))
993 result.Add(T);
994 }
995 }
996 return result.ToArray();
997 }
File name: PhotonViewInspector.cs
Copy
21 public override void OnInspectorGUI()
22 {
23 #if UNITY_3_5
24 EditorGUIUtility.LookLikeInspector();
25 #endif
26 //EditorGUI.indentLevel = 1;
27
28 m_Target = (PhotonView)this.target;
29 bool isProjectPrefab = EditorUtility.IsPersistent(m_Target.gameObject);
30
31 if( m_Target.ObservedComponents == null )
32 {
33 m_Target.ObservedComponents = new System.Collections.Generic.List
34 }
35
36 if( m_Target.ObservedComponents.Count == 0 )
37 {
38 m_Target.ObservedComponents.Add( null );
39 }
40
41 EditorGUILayout.BeginHorizontal();
42 // Owner
43 if (isProjectPrefab)
44 {
45 EditorGUILayout.LabelField("Owner:", "Set at runtime");
46 }
47 else if (m_Target.isSceneView)
48 {
49 EditorGUILayout.LabelField("Owner", "Scene");
50 }
51 else
52 {
53 PhotonPlayer owner = m_Target.owner;
54 string ownerInfo = (owner != null) ? owner.name : "
55
56 if (string.IsNullOrEmpty(ownerInfo))
57 {
58 ownerInfo = "
59 }
60
61 EditorGUILayout.LabelField("Owner", "[" + m_Target.ownerId + "] " + ownerInfo);
62 }
63
64 // ownership requests
65 EditorGUI.BeginDisabledGroup(Application.isPlaying);
66 m_Target.ownershipTransfer = (OwnershipOption)EditorGUILayout.EnumPopup(m_Target.ownershipTransfer, GUILayout.Width(100));
67 EditorGUI.EndDisabledGroup();
68
69 EditorGUILayout.EndHorizontal();
70
71
72 // View ID
73 if (isProjectPrefab)
74 {
75 EditorGUILayout.LabelField("View ID", "Set at runtime");
76 }
77 else if (EditorApplication.isPlaying)
78 {
79 EditorGUILayout.LabelField("View ID", m_Target.viewID.ToString());
80 }
81 else
82 {
83 int idValue = EditorGUILayout.IntField("View ID [1.."+(PhotonNetwork.MAX_VIEW_IDS-1)+"]", m_Target.viewID);
84 m_Target.viewID = idValue;
85 }
86
87
88
89 // Locally Controlled
90 if (EditorApplication.isPlaying)
91 {
92 string masterClientHint = PhotonNetwork.isMasterClient ? "(master)" : "";
93 EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, m_Target.isMine);
94 }
95
96
97
98 //DrawOldObservedItem();
99 ConvertOldObservedItemToObservedList();
100
101
102 // ViewSynchronization (reliability)
103 if (m_Target.synchronization == ViewSynchronization.Off)
104 {
105 GUI.color = Color.grey;
106 }
107
108 EditorGUILayout.PropertyField( serializedObject.FindProperty( "synchronization" ), new GUIContent( "Observe option:" ) );
109
110 if( m_Target.synchronization != ViewSynchronization.Off &&
111 m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0 )
112 {
113 GUILayout.BeginVertical( GUI.skin.box );
114 GUILayout.Label( "Warning", EditorStyles.boldLabel );
115 GUILayout.Label( "Setting the synchronization option only makes sense if you observe something." );
116 GUILayout.EndVertical();
117 }
118
119 /*ViewSynchronization vsValue = (ViewSynchronization)EditorGUILayout.EnumPopup("Observe option:", m_Target.synchronization);
120 if (vsValue != m_Target.synchronization)
121 {
122 m_Target.synchronization = vsValue;
123 if (m_Target.synchronization != ViewSynchronization.Off && m_Target.observed == null)
124 {
125 EditorUtility.DisplayDialog("Warning", "Setting the synchronization option only makes sense if you observe something.", "OK, I will fix it.");
126 }
127 }*/
128
129 DrawSpecificTypeSerializationOptions();
130
131 GUI.color = Color.white;
132 DrawObservedComponentsList();
133
134 // Cleanup: save and fix look
135 if (GUI.changed)
136 {
137 EditorUtility.SetDirty(m_Target);
138 PhotonViewHandler.HierarchyChange(); // TODO: check if needed
139 }
140
141 GUI.color = Color.white;
142 EditorGUIUtility.LookLikeControls();
143 }
File name: LoadbalancingPeer.cs
Copy
463 public virtual bool OpRaiseEvent(byte eventCode, object customEventContent, bool sendReliable, RaiseEventOptions raiseEventOptions)
464 {
465 opParameters.Clear(); // re-used private variable to avoid many new Dictionary() calls (garbage collection)
466 opParameters[(byte)LiteOpKey.Code] = (byte)eventCode;
467 if (customEventContent != null)
468 {
469 opParameters[(byte) LiteOpKey.Data] = customEventContent;
470 }
471
472 if (raiseEventOptions == null)
473 {
474 raiseEventOptions = RaiseEventOptions.Default;
475 }
476 else
477 {
478 if (raiseEventOptions.CachingOption != EventCaching.DoNotCache)
479 {
480 opParameters[(byte) LiteOpKey.Cache] = (byte) raiseEventOptions.CachingOption;
481 }
482 if (raiseEventOptions.Receivers != ReceiverGroup.Others)
483 {
484 opParameters[(byte) LiteOpKey.ReceiverGroup] = (byte) raiseEventOptions.Receivers;
485 }
486 if (raiseEventOptions.InterestGroup != 0)
487 {
488 opParameters[(byte) LiteOpKey.Group] = (byte) raiseEventOptions.InterestGroup;
489 }
490 if (raiseEventOptions.TargetActors != null)
491 {
492 opParameters[(byte) LiteOpKey.ActorList] = raiseEventOptions.TargetActors;
493 }
494 if (raiseEventOptions.ForwardToWebhook)
495 {
496 opParameters[(byte) ParameterCode.EventForward] = true; //TURNBASED
497 }
498 }
499
500 return this.OpCustom((byte)LiteOpCode.RaiseEvent, opParameters, sendReliable, raiseEventOptions.SequenceChannel, raiseEventOptions.Encrypt);
501 }
File name: BitmapFont.cs
Copy
26 public BitmapFont(string pathPNG, string pathXML, GameObject gameObject)
27 {
28 this.gameObject = gameObject;
29 sprites = new Dictionary
30 yoffsets_xadvances = new Dictionary
31 rects = new Dictionary
32
33 Texture2D texture = Resources.Load
34 float height = texture.height;
35 TextAsset xml = Resources.Load
36
37 XmlDocument test = new XmlDocument();
38 test.Load(new StringReader(xml.text));
39
40 //test.LoadXml(new StringReader(xml.text).ReadToEnd());
41 //string[] keys = new string[] {"x","y","width","height","yoffset","xadvance","letter"};
42
43 foreach (XmlNode node in test.DocumentElement.ChildNodes)
44 {
45 XmlAttributeCollection collection = node.Attributes;
46 Rect rect = new Rect(float.Parse(collection.Item(0).Value), height - float.Parse(collection.Item(1).Value) - float.Parse(collection.Item(3).Value), float.Parse(collection.Item(2).Value), float.Parse(collection.Item(3).Value));
47 rects.Add(collection.Item(6).Value, rect);
48 sprites.Add(collection.Item(6).Value, Sprite.Create(texture, rect, Vector2.zero));
49 yoffsets_xadvances.Add(collection.Item(6).Value, new Vector2(float.Parse(collection.Item(4).Value), float.Parse(collection.Item(5).Value)));
50 }
51 }
File name: frmSearchSach.cs
Copy
25 void AutoCompleteChuyenNganh(int i)
26 {
27 AutoCompleteStringCollection auto = new AutoCompleteStringCollection();
28 auto.Clear();
29 if (i == 0)
30 {
31 var tbDS = (from tb in db.tbDauSaches select tb.ChuyenNganh);
32 if (tbDS != null)
33 {
34 foreach (var item in tbDS)
35 {
36 auto.Add(item.Trim());
37 }
38 }
39 txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
40 txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
41 txtSearch.AutoCompleteCustomSource = auto;
42 }
43 if (i==1)
44 {
45 var tbDS = (from tb in db.tbDauSaches select tb.TenSach);
46 if (tbDS!=null)
47 {
48 foreach (var item in tbDS)
49 {
50 auto.Add(item.Trim());
51 }
52 }
53 txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
54 txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
55 txtSearch.AutoCompleteCustomSource = auto;
56 }
57 if (i==2)
58 {
59 var tbDS = (from tb in db.tbDauSaches
60 join tbtg in db.tbTGs on tb.MaTG equals tbtg.MaTG
61 select tbtg.TenTG);
62 if (tbDS !=null)
63 {
64 foreach (var item in tbDS)
65 {
66 auto.Add(item.Trim());
67 }
68 }
69 txtSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
70 txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
71 txtSearch.AutoCompleteCustomSource = auto;
72 }
73 if (i==3)
74 {
75 var tbDS = (from tb in db.tbDauSaches
76 join tbnxb in db.tbNXBs
77 on tb.MaNXB equals tbnxb.MaNXB
78 select tbnxb.TenNXB);
79 if (tbDS != null)
80 {
81 foreach (var item in tbDS)
82 {
83 auto.Add(item.Trim());
84 }
85 }
86 txtSearch.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
87 txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
88 txtSearch.AutoCompleteCustomSource = auto;
89 }
90 }
File name: frmTKDocGia.cs
Copy
19 void AutoComplete(int i)
20 {
21 AutoCompleteStringCollection auto = new AutoCompleteStringCollection();
22 if (i==1)
23 {
24 var tbDOCGIA = (
25 from tb in db.tbDGs
26 join tbTHE in db.tbThes on tb.MaDG equals tbTHE.MaDG
27 select tb.TenDG);
28 if (tbDOCGIA!=null)
29 {
30 foreach (var item in tbDOCGIA)
31 {
32 auto.Add(item.Trim());
33 }
34 }
35 txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
36 txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
37 txtSearch.AutoCompleteCustomSource = auto;
38 }
39 if (i==2)
40 {
41 var tbDOCGIA = (
42 from tb in db.tbDGs
43 join tbTHE in db.tbThes on tb.MaDG equals tbTHE.MaDG
44 select tb.MaDG);
45 if (tbDOCGIA != null)
46 {
47 foreach (var item in tbDOCGIA)
48 {
49 auto.Add(item.Trim());
50 }
51 }
52 txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
53 txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
54 txtSearch.AutoCompleteCustomSource = auto;
55 }
56 if (i==3)
57 {
58 var tbDOCGIA = (
59 from tb in db.tbDGs
60 join tbTHE in db.tbThes on tb.MaDG equals tbTHE.MaDG
61 select tbTHE.MaThe);
62 if (tbDOCGIA != null)
63 {
64 foreach (var item in tbDOCGIA)
65 {
66 auto.Add(item.Trim());
67 }
68 }
69 txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest;
70 txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource;
71 txtSearch.AutoCompleteCustomSource = auto;
72 }
73 }
File name: frmCategory.cs
Copy
131 private void Autocomplete()
132 {
133 try
134 {
135 con = new SqlConnection(cs.DBConn);
136 con.Open();
137 SqlCommand cmd = new SqlCommand("SELECT distinct Categoryname FROM Category", con);
138 DataSet ds = new DataSet();
139 SqlDataAdapter da = new SqlDataAdapter(cmd);
140 da.Fill(ds, "Category");
141 AutoCompleteStringCollection col = new AutoCompleteStringCollection();
142 int i = 0;
143 for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
144 {
145 col.Add(ds.Tables[0].Rows[i]["Categoryname"].ToString());
146
147 }
148 txtCategoryName.AutoCompleteSource = AutoCompleteSource.CustomSource;
149 txtCategoryName.AutoCompleteCustomSource = col;
150 txtCategoryName.AutoCompleteMode = AutoCompleteMode.Suggest;
151
152 con.Close();
153 }
154 catch (Exception ex)
155 {
156 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
157 }
158 }
File name: frmProduct.cs
Copy
215 private void Autocomplete()
216 {
217 try
218 {
219 con = new SqlConnection(cs.DBConn);
220 con.Open();
221 SqlCommand cmd = new SqlCommand("SELECT distinct ProductName FROM product", con);
222 DataSet ds = new DataSet();
223 SqlDataAdapter da = new SqlDataAdapter(cmd);
224 da.Fill(ds, "Product");
225 AutoCompleteStringCollection col = new AutoCompleteStringCollection();
226 int i = 0;
227 for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
228 {
229 col.Add(ds.Tables[0].Rows[i]["productname"].ToString());
230
231 }
232 txtProductName.AutoCompleteSource = AutoCompleteSource.CustomSource;
233 txtProductName.AutoCompleteCustomSource = col;
234 txtProductName.AutoCompleteMode = AutoCompleteMode.Suggest;
235
236 con.Close();
237 }
238 catch (Exception ex)
239 {
240 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
241 }
242 }
File name: frmRegistration.cs
Copy
276 private void Autocomplete()
277 {
278 try{
279 con = new SqlConnection(cs.DBConn);
280 con.Open();
281 SqlCommand cmd = new SqlCommand("SELECT username FROM registration", con);
282 DataSet ds = new DataSet();
283 SqlDataAdapter da = new SqlDataAdapter(cmd);
284 da.Fill(ds, "registration");
285 AutoCompleteStringCollection col = new AutoCompleteStringCollection();
286 int i = 0;
287 for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
288 {
289 col.Add(ds.Tables[0].Rows[i]["Username"].ToString());
290
291 }
292 txtUsername.AutoCompleteSource = AutoCompleteSource.CustomSource;
293 txtUsername.AutoCompleteCustomSource = col;
294 txtUsername.AutoCompleteMode = AutoCompleteMode.Suggest;
295
296 con.Close();
297 }
298 catch (Exception ex)
299 {
300 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
301 }
302 }
File name: frmSubCategory.cs
Copy
94 private void Autocomplete()
95 {
96 try
97 {
98 con = new SqlConnection(cs.DBConn);
99 con.Open();
100 SqlCommand cmd = new SqlCommand("SELECT distinct SubCategoryName FROM SubCategory", con);
101 DataSet ds = new DataSet();
102 SqlDataAdapter da = new SqlDataAdapter(cmd);
103 da.Fill(ds, "SubCategory");
104 AutoCompleteStringCollection col = new AutoCompleteStringCollection();
105 int i = 0;
106 for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
107 {
108 col.Add(ds.Tables[0].Rows[i]["SubCategoryName"].ToString());
109
110 }
111 txtSubCategory.AutoCompleteSource = AutoCompleteSource.CustomSource;
112 txtSubCategory.AutoCompleteCustomSource = col;
113 txtSubCategory.AutoCompleteMode = AutoCompleteMode.Suggest;
114
115 con.Close();
116 }
117 catch (Exception ex)
118 {
119 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
120 }
121 }
Collection 105 lượt xem
Gõ tìm kiếm nhanh...