UPDATE!!!
Found a work around:
First add this line on top of your OnGUI(). Don’t worry about any errors, the next code should fix it. It doesn’t throw anything to me.
GUI.EndClip()
DrawTitleBar();
Rect clippingRect = new Rect(0, 0, Screen.width, Screen.height);
Vector2 scrollOffset = new Vector2(0, 0);
Vector2 renderOffset = new Vector2(0, 21f);
GUI.BeginClip(clippingRect, scrollOffset, renderOffset, false);
Where DrawTitleBar redraws the title bar like this (grab the icons from GitHub - halak/unity-editor-icons)
void DrawTitleBar()
{
Rect titleBarRect = new Rect(0, 0, currentWindow.position.width, 21f);
//GUI.EndGroup();
GUI.BeginGroup(titleBarRect);
//Draw Title Bar Background
EditorGUI.DrawRect(titleBarRect, softBlack);
EditorGUILayout.BeginHorizontal();
//Draw Title name
var titleSize = GUI.skin.label.CalcSize(new GUIContent("Title Name"));
Rect titleBarNameRect = new Rect(0, 0, titleSize.x + 16, 21f);
Rect titleBarNameTitleRect = new Rect(5, 0, titleSize.x + 16, 21f);
EditorGUI.DrawRect(titleBarNameRect, softGray);
GUIStyle myTextAreaStyle = new GUIStyle(EditorStyles.label);
Handles.color = softRed;
Handles.DrawLine(new Vector2(0, 1), new Vector3(titleSize.x + 15, 1));
//myTextAreaStyle.alignment = note.alignment;
myTextAreaStyle.normal.textColor = softWhite;
GUILayout.BeginArea(titleBarNameTitleRect);
EditorGUILayout.LabelField("Title Name", myTextAreaStyle);
GUILayout.EndArea();
Rect middleRect = new Rect(titleBarNameRect.width + 1, 0, currentWindow.position.width - titleBarNameRect.width - 52, 21f);
EditorGUI.DrawRect(middleRect, softBlack);
GUIStyle titleBarButtonStyle = new GUIStyle(EditorStyles.iconButton);
titleBarButtonStyle.alignment = TextAnchor.UpperCenter;
Rect minimizeRect = new Rect(currentWindow.position.width + 1 - 52, 0, 16, 21f);
Rect maximizeRect = new Rect(currentWindow.position.width + 1 - 35, 0, 16, 21f);
Rect closeRect = new Rect(currentWindow.position.width + 1 - 18, 0, 16, 21f);
GUI.Button(minimizeRect, minimizeIcon.texture, titleBarButtonStyle);
// currentWindow ? restoreIcon.texture : maximizeIcon.texture;
if (currentWindow.position.width == Screen.currentResolution.width) maxIcon = restoreIcon.texture;
else maxIcon = maximizeIcon.texture;
GUI.Button(maximizeRect, maxIcon, titleBarButtonStyle);
GUI.Button(closeRect, closeIcon.texture, titleBarButtonStyle);
EditorGUILayout.EndHorizontal();
GUI.EndGroup();
}
Attention! This is important part. After doing all this, you will notice that the titlebar is ok, but everything underneath needs to be moved by 21f pixels (titlebar’s height) down. So after the first GUI.EndClip() and before the DrawTitlebar() call put this two lines:
//Right after GUI.EndClip()
GUI.BeginGroup(new Rect(0,21f,Screen.width,Screen.height));
//Your drawing part underneath titlebar
//Right before DrawTItlebar()
GUI.EndGroup();
Hope this helps!