Find All GameObjects currently that are in the Hierarchy Window view

I’m writing a custom inspector for the Hierarchy but the script gets bogged down because EditorApplication.HierarchyWindowItemOnGUI goes through and draws every gameObject whether or not it is currently viewed on screen. I’d like to check and see if they are actually visible and in the Window’s view in the hierarchy.

Figured it out.

EditorWindow _wnd = EditorWindow.GetWindow(WndType, false, "Hierarchy", false);

static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
        {
            UnityEngine.Object obj = EditorUtility.InstanceIDToObject(instanceID);
            if (obj == null || obj.hideFlags.Has(HideFlags.HideInInspector) || obj.hideFlags.Has(HideFlags.HideInInspector))
            {
                return;
            }

            if (HierarchyWindow.position.height < selectionRect.y &&
                0 > selectionRect.y)
            {
                return;
            }