How to add a custom button to the top right corner of a editor window?

Hello guys, is there any way to add a custom button to the right of editor window’s toolbar?
(just like help url 7973397--1023024--upload_2022-3-18_10-32-13.png)

7973397--1023018--upload_2022-3-18_10-19-43.png

[Solved] There is a Unity message “ShowButton(Rect position)” that can be used to draw UI on EditorWindow’s toolbar. This message was not mentioned in Unity document page.

public class MyWindow : EditorWindow
{
    private GUIStyle _toolbarButtonStyle;

    [MenuItem("Test/My Window")]
    public static void Open()
    {
        EditorWindow.GetWindow<MyWindow>();
    }

    /// <summary>
    /// Draw buttons on toolbar.
    /// Automatically called by unity.
    /// </summary>
    /// <param name="position"></param>
    private void ShowButton(Rect position)
    {
        // button style
        if (_toolbarButtonStyle == null)
        {
            _toolbarButtonStyle = new GUIStyle(GUI.skin.button)
            {
                padding = new RectOffset()
            };
        }

        // draw button
        if (GUI.Button(position, EditorGUIUtility.IconContent("_Help"), _toolbarButtonStyle))
        {
            Application.OpenURL("https://docs.unity3d.com/Manual/index.html");
        }
    }
}
7 Likes

7973853--1023114--upload_2022-3-18_16-55-47.png

1 Like

Thanks! Very useful

Hello there ! Does anyone know if an equivalent exists for component header toolbar ? :slight_smile:

8639895--1161993--upload_2022-12-6_16-49-14.png

According to these codes, there are well done, although I used GuiLayout.Buttont(); but the style code and iconContent code are very helpful

Simplified code and corrected button style (removing the gray background of the button):

private void ShowButton(Rect position)
{
    // draw button
    if (GUI.Button(position, EditorGUIUtility.IconContent("_Help"), GUI.skin.FindStyle("IconButton")))
    {
        Application.OpenURL("https://docs.unity3d.com/Manual/index.html");
    }
}
1 Like

9732769--1391911--upload_2024-3-28_11-27-11.png