Selecting a Foldout Button? and Dragging it?

I’m trying to make a tool that will have hierarchy functionality along with some other custom behavior.

I can get the view working pretty well, using IndentLevel and Foldouts. However I want to be able to select items, and move them around (by dragging, same way it is done in the Hierarchy panel).

I know I’ll have to manage the selections my self, which is fine.

How do I make a Foldout button that can be selected? ( just like the Hierarchy) and how to manage the drag and drop to rearrange the Hierarchy?

Is there anyway to actually just duplicate the Hierarchy, or subclass it and provide some custom behavior?

@zeenobit → answering my own question so its documented.

I ended up drawing my own custom gui in an editor window.

To produce the “selection” I wrapped the folder call with a BeginHorizontal(), which returns a rect, which allows you to check if that part of gui was clicked. then, i would just update the GUIStyle the horizontal is using, so the background appears selected.

using this technique, you can apply any mouse operation to any “row” of your gui.

Sorry that I have no access to the code I wrote at the time to provide a sample.