The Inspector and Project windows both have lock icons beside their context menu buttons, like this:
I’m going to demonstrate how to make one for your own EditorWindow. Simply implement the method ShowButton(Rect rect), and handle a button in there. Some code:
public class ShowButtonEditorWindow : EditorWindow
private GUIStyle m_IconStyle = new GUIStyle();
private void OnEnable()
//NOTE: this is the little pac man from the game view tab
Texture2D icon = EditorGUIUtility.FindTexture("UnityEditor.GameView");
m_IconStyle.normal.background = icon;
private void ShowButton(Rect rect)
if (GUI.Button(rect, GUIContent.none, m_IconStyle))
Debug.Log("Icon clicked: " + rect);
//NOTE: you /could/ add extra buttons like this, but
// unity doesn't really make room for that, so
// there will be some anomalies
//rect.x -= 16.0f;
//if (GUI.Button(rect, GUIContent.none, m_IconStyle))
// Debug.Log("Icon clicked");
[MenuItem("Tools/Show Button Window")]
public static void Init_ToolsMenu()
EditorWindow window = EditorWindow.GetWindow<ShowButtonEditorWindow>();
window.title = "Show Button";
This will create a button that has the little Pac Man icon from the Game View window that, when clicked, simply spits out a debug log message.
The code that goes inside the body of ShowButton is completely up to you. It’s probably best to stick to the GUI functions and avoid all of the layout stuff.
I’d like to add some notes here about the Rect that is passed to ShowButton. It is created by the Unity Editor’s internal code, and is intended to be used as-is without modification. The x and y are automatically set for you and the dimensions are 16×16. You could technically change the values of the Rect to whatever you want. It’s not really advantageous to do so since it’s possible that the button will not fit correctly into the titlebar. The example code I’ve listed has a commented out section that demonstrates how to make a second button. If you are curious, uncomment that section and open the window. Resize the window to its smallest. Notice the overlap?
I can’t recommend doing this, especially if you’re making a tool that will go on the Asset Store. It’s your window, however, so if you need this for whatever reason, it’s available.