AddRange
How do I use Add Range
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: ChatGui.cs
Copy
103 public void OnGUI()
104 {
105 if (!this.IsVisible)
106 {
107 return;
108 }
109
110 GUI.skin.label.wordWrap = true;
111 //GUI.skin.button.richText = true; // this allows toolbar buttons to have bold/colored text. nice to indicate new msgs
112 //GUILayout.Button("lala"); // as richText, html tags could be in text
113
114
115 if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
116 {
117 if ("ChatInput".Equals(GUI.GetNameOfFocusedControl()))
118 {
119 // focus on input -> submit it
120 GuiSendsMsg();
121 return; // showing the now modified list would result in an error. to avoid this, we just skip this single frame
122 }
123 else
124 {
125 // assign focus to input
126 GUI.FocusControl("ChatInput");
127 }
128 }
129
130 GUI.SetNextControlName("");
131 GUILayout.BeginArea(this.GuiRect);
132
133 GUILayout.FlexibleSpace();
134
135 if (this.chatClient.State != ChatState.ConnectedToFrontEnd)
136 {
137 GUILayout.Label("Not in chat yet.");
138 }
139 else
140 {
141 List
142 int countOfPublicChannels = channels.Count;
143 channels.AddRange(this.chatClient.PrivateChannels.Keys);
144
145 if (channels.Count > 0)
146 {
147 int previouslySelectedChannelIndex = this.selectedChannelIndex;
148 int channelIndex = channels.IndexOf(this.selectedChannelName);
149 this.selectedChannelIndex = (channelIndex >= 0) ? channelIndex : 0;
150
151 this.selectedChannelIndex = GUILayout.Toolbar(this.selectedChannelIndex, channels.ToArray(), GUILayout.ExpandWidth(false));
152 this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
153
154 this.doingPrivateChat = (this.selectedChannelIndex >= countOfPublicChannels);
155 this.selectedChannelName = channels[this.selectedChannelIndex];
156
157 if (this.selectedChannelIndex != previouslySelectedChannelIndex)
158 {
159 // changed channel -> scroll down, if private: pre-fill "to" field with target user's name
160 this.scrollPos.y = float.MaxValue;
161 if (this.doingPrivateChat)
162 {
163 string[] pieces = this.selectedChannelName.Split(new char[] {':'}, 3);
164 this.userIdInput = pieces[1];
165 }
166 }
167
168 GUILayout.Label(ChatGui.WelcomeText);
169
170 if (this.chatClient.TryGetChannel(selectedChannelName, this.doingPrivateChat, out this.selectedChannel))
171 {
172 for (int i = 0; i < this.selectedChannel.Messages.Count; i++)
173 {
174 string sender = this.selectedChannel.Senders[i];
175 object message = this.selectedChannel.Messages[i];
176 GUILayout.Label(string.Format("{0}: {1}", sender, message));
177 }
178 }
179
180 GUILayout.EndScrollView();
181 }
182 }
183
184
185 GUILayout.BeginHorizontal();
186 if (doingPrivateChat)
187 {
188 GUILayout.Label("to:", GUILayout.ExpandWidth(false));
189 GUI.SetNextControlName("WhisperTo");
190 this.userIdInput = GUILayout.TextField(this.userIdInput, GUILayout.MinWidth(100), GUILayout.ExpandWidth(false));
191 string focussed = GUI.GetNameOfFocusedControl();
192 if (focussed.Equals("WhisperTo"))
193 {
194 if (this.userIdInput.Equals("username"))
195 {
196 this.userIdInput = "";
197 }
198 }
199 else if (string.IsNullOrEmpty(this.userIdInput))
200 {
201 this.userIdInput = "username";
202 }
203
204 }
205 GUI.SetNextControlName("ChatInput");
206 inputLine = GUILayout.TextField(inputLine);
207 if (GUILayout.Button("Send", GUILayout.ExpandWidth(false)))
208 {
209 GuiSendsMsg();
210 }
211 GUILayout.EndHorizontal();
212 GUILayout.EndArea();
213 }
File name: PhotonConverter.cs
Copy
142 public static List143 {
144 List
145
146 try
147 {
148 scripts.AddRange(Directory.GetFiles(folder, "*.cs", SearchOption.AllDirectories));
149 scripts.AddRange(Directory.GetFiles(folder, "*.js", SearchOption.AllDirectories));
150 scripts.AddRange(Directory.GetFiles(folder, "*.boo", SearchOption.AllDirectories));
151 }
152 catch (System.Exception ex)
153 {
154 Debug.Log("Getting script list from folder " + folder + " failed. Exception:\n" + ex.ToString());
155 }
156
157 return scripts;
158 }
File name: PhotonEditor.cs
Copy
909 public static void UpdateRpcList()
910 {
911 List
912 HashSet
913
914 var types = GetAllSubTypesInScripts(typeof(MonoBehaviour));
915
916 foreach (var mono in types)
917 {
918 MethodInfo[] methods = mono.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
919
920 foreach (MethodInfo method in methods)
921 {
922 if (method.IsDefined(typeof(UnityEngine.RPC), false))
923 {
924 currentRpcs.Add(method.Name);
925
926 if (!additionalRpcs.Contains(method.Name) && !PhotonEditor.Current.RpcList.Contains(method.Name))
927 {
928 additionalRpcs.Add(method.Name);
929 }
930 }
931 }
932 }
933
934 if (additionalRpcs.Count > 0)
935 {
936 // LIMITS RPC COUNT
937 if (additionalRpcs.Count + PhotonEditor.Current.RpcList.Count >= byte.MaxValue)
938 {
939 if (currentRpcs.Count <= byte.MaxValue)
940 {
941 bool clearList = EditorUtility.DisplayDialog(CurrentLang.IncorrectRPCListTitle, CurrentLang.IncorrectRPCListLabel, CurrentLang.RemoveOutdatedRPCsLabel, CurrentLang.CancelButton);
942 if (clearList)
943 {
944 PhotonEditor.Current.RpcList.Clear();
945 PhotonEditor.Current.RpcList.AddRange(currentRpcs);
946 }
947 else
948 {
949 return;
950 }
951 }
952 else
953 {
954 EditorUtility.DisplayDialog(CurrentLang.FullRPCListTitle, CurrentLang.FullRPCListLabel, CurrentLang.SkipRPCListUpdateLabel);
955 return;
956 }
957 }
958
959 additionalRpcs.Sort();
960 PhotonEditor.Current.RpcList.AddRange(additionalRpcs);
961 EditorUtility.SetDirty(PhotonEditor.Current);
962 }
963 }
File name: ChatChannel.cs
Copy
53 public void Add(string[] senders, object[] messages)
54 {
55 this.Senders.AddRange(senders);
56 this.Messages.AddRange(messages);
57 }
File name: Tiled2UnityMenuItems.cs
Copy
17 static void ExportLibrary()
18 {
19 string name = String.Format("Tiled2Unity.{0}.unitypackage", ImportTiled2Unity.ThisVersion);
20 var path = EditorUtility.SaveFilePanel("Save texture as PNG", "", name, "unitypackage");
21 if (path.Length != 0)
22 {
23 List
24 packageFiles.AddRange(EnumerateAssetFilesAt("Assets/Tiled2Unity", ".cs", ".shader", ".txt"));
25 AssetDatabase.ExportPackage(packageFiles.ToArray(), path);
26 }
27 }
File name: frmMain.cs
Copy
59 private void InitializeComponent()
60 {
61 this.components = new System.ComponentModel.Container();
62 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
63 this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
64 this.menuItem1 = new System.Windows.Forms.MenuItem();
65 this.FileLoad = new System.Windows.Forms.MenuItem();
66 this.FileSave = new System.Windows.Forms.MenuItem();
67 this.FileExit = new System.Windows.Forms.MenuItem();
68 this.menuItem4 = new System.Windows.Forms.MenuItem();
69 this.FilterGrayScale = new System.Windows.Forms.MenuItem();
70 this.FilterColor = new System.Windows.Forms.MenuItem();
71 this.menuItem3 = new System.Windows.Forms.MenuItem();
72 this.EmbossLaplacian = new System.Windows.Forms.MenuItem();
73 this.EdgeDetectQuick = new System.Windows.Forms.MenuItem();
74 this.SuspendLayout();
75 //
76 // mainMenu1
77 //
78 this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
79 this.menuItem1,
80 this.menuItem4,
81 this.menuItem3});
82 //
83 // menuItem1
84 //
85 this.menuItem1.Index = 0;
86 this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
87 this.FileLoad,
88 this.FileSave,
89 this.FileExit});
90 this.menuItem1.Text = "File";
91 //this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
92 //
93 // FileLoad
94 //
95 this.FileLoad.Index = 0;
96 this.FileLoad.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
97 this.FileLoad.Text = "Mở file";
98 this.FileLoad.Click += new System.EventHandler(this.File_Load);
99 //
100 // FileSave
101 //
102 this.FileSave.Index = 1;
103 this.FileSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
104 this.FileSave.Text = "Lưu file";
105 this.FileSave.Click += new System.EventHandler(this.File_Save);
106 //
107 // FileExit
108 //
109 this.FileExit.Index = 2;
110 this.FileExit.Text = "Thoát";
111 this.FileExit.Click += new System.EventHandler(this.File_Exit);
112 //
113 // menuItem4
114 //
115 this.menuItem4.Index = 1;
116 this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
117 this.FilterGrayScale,
118 this.FilterColor});
119 this.menuItem4.Text = "Biến đổi màu";
120 //
121 // FilterGrayScale
122 //
123 this.FilterGrayScale.Index = 0;
124 this.FilterGrayScale.Text = "Xám";
125 this.FilterGrayScale.Click += new System.EventHandler(this.Filter_GrayScale);
126 //
127 // FilterColor
128 //
129 this.FilterColor.Index = 1;
130 this.FilterColor.Text = "Màu";
131 this.FilterColor.Click += new System.EventHandler(this.Filter_Color);
132 //
133 // menuItem3
134 //
135 this.menuItem3.Index = 2;
136 this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
137 this.EmbossLaplacian,
138 this.EdgeDetectQuick});
139 this.menuItem3.Text = "Phát hiện biên";
140 //this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
141 //
142 // EmbossLaplacian
143 //
144 this.EmbossLaplacian.Index = 0;
145 this.EmbossLaplacian.Text = "Laplacian_Emboss";
146 this.EmbossLaplacian.Click += new System.EventHandler(this.OnEmbossLaplacian);
147 //
148 // EdgeDetectQuick
149 //
150 this.EdgeDetectQuick.Index = 1;
151 this.EdgeDetectQuick.Text = "EdgeDetectQuick";
152 this.EdgeDetectQuick.Click += new System.EventHandler(this.OnEdgeDetectQuick);
153 //
154 // frmMain
155 //
156 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
157 this.BackColor = System.Drawing.SystemColors.ControlLightLight;
158 this.BackgroundImage = global::CSharpFilters.Properties.Resources.Daewoo;
159 this.ClientSize = new System.Drawing.Size(349, 237);
160 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
161 this.Menu = this.mainMenu1;
162 this.Name = "frmMain";
163 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
164 this.Text = "Xu ly anh";
165 //this.Load += new System.EventHandler(this.Form1_Load);
166 this.ResumeLayout(false);
167
168 }
AddRange 103 lượt xem
Gõ tìm kiếm nhanh...