/// <summary> /// Draws an editor for the custom tag system for the GameObject class. /// </summary> private void DrawTagSystem() { // If editing game object(s) tag has changed, update its tags if (targetGO.Select(g => g.tag) != lastTags) { GetObjectsTags(); Repaint(); } EditorGUILayout.BeginHorizontal(); // Title of the tag section EditorGUILayout.LabelField(new GUIContent("Tags"), EditorStyles.boldLabel); // Creates a button at the top right of the inspector to open the tags editor window // First, get its rect, then draw it Rect _editButtonRect = GUILayoutUtility.GetRect(new GUIContent("Edit Tags"), EditorStyles.miniButtonRight, GUILayout.Width(100)); if (GUI.Button(_editButtonRect, "Edit Tags", EditorStyles.miniButtonRight)) { TagsEditorWindow.CallWindow(); } EditorGUILayout.EndHorizontal(); // Draws the tag section for editing objects if (isUnfolded) { // Draws a tags field, to edit tag from editing object(s) Action <Tag> _addTagCallback = new Action <Tag>((Tag _tag) => MultiTagsUtility.AddTagToGameObjects(_tag, targetGO)); Action <Tag> _removeTagCallback = new Action <Tag>((Tag _tag) => MultiTagsUtility.RemoveTagFromGameObjects(_tag, targetGO)); MultiTagsUtility.GUILayoutTagsField(editingTags, _addTagCallback, _removeTagCallback, true); if (haveTargetsDifferentTags) { EditorGUILayout.HelpBox("You are editing Game Objects with different tags.\n" + "Only tags in common will be displayed in the inspector.", MessageType.Info); } } // Males a space in the editor to finish GUILayout.Space(7); }
/// <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); } }