/// <summary> /// Draws the toolbar on the top of the tags editor window. /// </summary> private void DrawToolbar() { GUILayout.BeginHorizontal(EditorStyles.toolbar); // Draws a button to create a brand new cool tag if (GUILayout.Button("Create Tag", EditorStyles.toolbarButton)) { CreateTagWindow.CallWindow(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
void createCommand() { CreateTagWindow window = new CreateTagWindow(); window.Closed += (s, args) => { if (window.DialogResult.Value) { var has = this.Tags.Any(c => { return(window.Tags.Any(cc => cc.Equals(c.Name))); }); if (has) { var result = this.ShowDialog("提示信息", "存在相同标签,是否继续添加", CustomControl.Enums.DialogSettingType.OkAndCancel, CustomControl.Enums.DialogType.Warning); if (result != CustomControl.Enums.DialogResultType.OK) { return; } } var cl = base.GetClCase(base.LocalID); foreach (var t in window.Tags) { var tagID = this.Tags.Count == 0 ? 0 : this.Tags.Max(tt => Convert.ToInt64(tt.ID)); // 创建 TagModel tag = new TagModel() { ID = (tagID + 1).ToString(), Name = t, }; // 更新UI this.Tags.Add(new UITag { ID = tag.ID, Name = tag.Name, }); // 更新缓存 cl.Tags.Add(tag); } base.Serialize(cl, LocalID); } }; window.ShowDialog(); }
/// <summary> /// Displays the tags of the project. /// </summary> public void DrawTags() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); GUILayout.Space(10); // Draws a header EditorGUILayout.LabelField("Unity built-in Tags", EditorStyles.boldLabel); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); // Draw a button on top right to connect project tags if (GUILayout.Button(new GUIContent("Connect Project Tags", "Use this if Unity tags or tags on this asset have been created without using this editor ;\nThis will connect this project Unity tags with the tags asset to create missing tags on both of them."), GUILayout.Width(150), GUILayout.Height(25))) { ConnectProjectTags(); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); // If no tags, draws a information box and return if (tagsSO.UnityBuiltInTags == null || tagsSO.UnityBuiltInTags.ObjectTags.Length == 0) { EditorGUILayout.HelpBox("No built-in tag found on this project", MessageType.Info); } else { // Draw Unity built-in tags MultiTagsUtility.GUILayoutDisplayTags(tagsSO.UnityBuiltInTags.ObjectTags); } GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); // Draws a header with a little plus button next to it, allowing to create new tags GUIContent _customTags = new GUIContent("Custom Tags", "Tags created by users on this project"); EditorGUILayout.LabelField(_customTags, EditorStyles.boldLabel, GUILayout.MaxWidth(EditorStyles.boldLabel.CalcSize(_customTags).x)); GUIStyle _olPlus = MultiTagsUtility.OLPlusStyle; Rect _buttonRect = GUILayoutUtility.GetRect(GUIContent.none, _olPlus); _buttonRect.y += 2; if (GUI.Button(_buttonRect, new GUIContent(string.Empty, "Create a new tag on this project"), _olPlus)) { CreateTagWindow.CallWindow(); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); // If no tags, draws a information box and return if (tagsSO.CustomTags == null || tagsSO.CustomTags.ObjectTags.Length == 0) { EditorGUILayout.HelpBox("No tag found on this project. How about create a first one ?", MessageType.Info); } else { // Draw all custom tags ; if clicking on a tag left button, remove it from the project and repaint MultiTagsUtility.GUILayoutTagsField(tagsSO.CustomTags.ObjectTags, RemoveTag); } }