/// <summary> /// Adds the tag game objects. /// </summary> /// <param name="tag">The tag.</param> /// <param name="activeGameObjects">The active game objects.</param> private void AddTagGameObjects(string tag, params GameObject[] activeGameObjects) { TagManager.AddTags(activeGameObjects, tag); TagManager.RefreshTags(); }
/// <summary> /// Draws the tag find. /// </summary> private void DrawTagFind() { EditorGUILayout.BeginHorizontal(); GUIContent findTagFoldoutContent = new GUIContent(string.Format("Find tags")); GUIStyle findTagFoldoutStyle = new GUIStyle(EditorStyles.foldout); this.findTagFoldout.target = EditorGUILayout.Foldout(this.findTagFoldout.target, findTagFoldoutContent, findTagFoldoutStyle); GUILayout.FlexibleSpace(); if (GUILayout.Button(string.Empty, CustomEditorStyles.HelpIconStyle)) { Application.OpenURL("http://aiunity.com/products/multiple-tags/manual#gui-find-tags"); } EditorGUILayout.EndHorizontal(); if (EditorGUILayout.BeginFadeGroup(this.findTagFoldout.faded)) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); GUIStyle findCategoryStyle = new GUIStyle(EditorStyles.radioButton); findCategoryStyle.margin.left = 0; findCategoryStyle.margin.right = 0; EditorGUILayout.PrefixLabel("Tag category"); string[] tagCategories = Enum.GetNames(typeof(TagCategory)); this.tagCategory = (TagCategory)GUILayout.SelectionGrid((int)this.tagCategory, tagCategories, tagCategories.Length, findCategoryStyle); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUIContent findTagContent = new GUIContent("Tag expression", "Find Unity tags matching this expression. The expression can use text, regex, and boolean logic. Click the + sign to see available syntax and tags. The expression complexity can range from \"Tag1\" to \"(Tag1 & Tag2.*) | Tag3\". An empty expression is a special case that denotes all tags (ie. .*)."); EditorGUILayout.PrefixLabel(findTagContent); GUIStyle findTagStyle = new GUIStyle(EditorStyles.textField) { wordWrap = true }; foreach (string tagPath in this.TagSelected.Where(p => p.Value).Select(p => p.Key).Except(this.findTagPaths.Select(p => TagService.JoinTags(p))).ToList()) { this.TagSelected[tagPath] = false; } if (!this.findTagExpressionValid) { GUI.backgroundColor = Color.red; } GUI.SetNextControlName("FindTagExpression"); this.findTagExpression.text = GUILayout.TextField(this.findTagExpression.text, findTagStyle); GUI.backgroundColor = Color.white; bool addLayout = GUILayout.Button(string.Empty, CustomEditorStyles.PlusIconStyle); if (Event.current.type == EventType.Repaint) { this.findGameObjectMenuRect = GUILayoutUtility.GetLastRect(); } if (addLayout) { EditorGUI.FocusTextInControl("FindTagExpression"); GenericMenu findMenu = CreateFindMenu(this.findTagExpression); findMenu.DropDown(this.findGameObjectMenuRect); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; try { Regex.Match(string.Empty, this.findTagExpression.text); this.findTagPaths = string.IsNullOrEmpty(this.findTagExpression.text) ? TagService.AllTagPaths : TagService.GetTagPathMatches(this.findTagExpression.text); this.findTagExpressionValid = true; } catch (ArgumentException) { this.findTagExpressionValid = false; } if (this.findTagPaths.Any()) { EditorGUILayout.Space(); this.tagFindScroll = EditorGUILayout.BeginScrollView(this.tagFindScroll, false, false); GUIStyle tagHeaderStyle = new GUIStyle(EditorStyles.label); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); EditorGUILayout.BeginVertical("box"); bool tagSelectAll = this.TagSelected.All(p => p.Value || TagService.FixedTags.Any(f => f == p.Key)); bool tagSelectAllUpdate = EditorGUILayout.ToggleLeft("Select All", tagSelectAll, tagHeaderStyle); if (tagSelectAllUpdate ^ tagSelectAll) { this.TagSelected = this.TagSelected.ToDictionary(p => p.Key, p => tagSelectAllUpdate && !TagService.FixedTags.Any(f => f == p.Key)); } foreach (string tagPath in this.findTagPaths.Select(p => TagService.JoinTags(p)).Reverse()) { EditorGUILayout.BeginHorizontal(); int tagPathCount = 0; TagManager.TagPathCount.TryGetValue(tagPath, out tagPathCount); if (this.tagCategory == TagCategory.All || (this.tagCategory == TagCategory.Used && tagPathCount > 0) || (this.tagCategory == TagCategory.Unused && tagPathCount == 0)) { EditorGUI.BeginDisabledGroup(TagService.FixedTags.Any(f => f == tagPath)); GUIContent tagSelectedContent = new GUIContent(string.Format("({0}) {1}", tagPathCount, tagPath)); bool tagSelected = this.TagSelected[tagPath] = this.TagSelected.TryGetValue(tagPath, out tagSelected) && tagSelected; this.TagSelected[tagPath] = EditorGUILayout.ToggleLeft(tagSelectedContent, tagSelected, tagHeaderStyle); EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndHorizontal(); } EditorGUIUtility.labelWidth = 0; EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); GUIContent tagAddContent = new GUIContent("Add", "Add tags to unity."); if (GUILayout.Button(tagAddContent)) { CreateTagPopup(tag => TagManager.AddTags(tag)); TagManager.RefreshTags(); } GUIContent deleteGUIContent = new GUIContent("Delete"); if (GUILayout.Button(deleteGUIContent)) { bool tagSelected = false; foreach (IEnumerable <string> tagPath in this.findTagPaths.Where(p => this.TagSelected.TryGetValue(TagService.JoinTags(p), out tagSelected) && tagSelected)) { TagManager.RemoveTags(tagPath.ToArray()); RefreshTags(); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndFadeGroup(); }