Beispiel #1
0
    /// <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);
        }
    }