How to get inspector size / rect for Custom Editor?


I know two ways to get the width of the visible area of the inspector window:

(float)typeof(EditorGUIUtility).GetProperty("contextWidth", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null, null);

But it does return the width, including the scrollView if it has one (some of my content is overlapping the scrollView).
I could draw the scroll myself when I need to, but the problem is that I can’t get the height!

I can calculate the width using GUILayoutUtility.GetRect but in the first lifecycle it returns Rect(0,0,1,1)
And when the window is resized, the GUILayout methods fall behind. It looks terrible.

How do I get the size of the inspector window?

Right now I’m using this crutch:

var width = EditorGUIUtility.currentViewWidth;
var height = Screen.height * (width / Screen.width) - 160;

160 = Inspector title height + Assets labels (for ScriptableObject)