Hello guys, is there any way to add a custom button to the right of editor window’s toolbar?
(just like help url )
[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
1 Like
Thanks! Very useful
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