- Home /
Question by
MaxPirat · Apr 16, 2017 at 12:57 PM ·
editoreditor-scriptinghierarchy
Custom Hierarchy background rect lines
How can I draw bg rect lines to seperate elements in Hierarchy window? Like in this plugin for example:
I tried with a function on EditorApplication.hierarchyWindowItemOnGUI event, but I have to draw all lines at one time so I'm using bool redraw to know if I should redraw bg this time.
...
EditorApplication.update += Update;
EditorApplication.hierarchyWindowItemOnGUI += DrawHierarchyBG;
...
static void Update()
{
needRedraw = true;
}
static void DrawHierarchyBG(int instanceId, Rect selectionRect)
{
if (needRedraw)
{
needRedraw = false;
int numberOfLines = Screen.height / 16;
for (int i = 0; i < numberOfLines; i+=2)
{
GUI.backgroundColor = new Color(.5f, .5f, .5f, .1f);
Rect grayRect = new Rect(0, 16 * i, Screen.width, 16);
GUI.Box(grayRect, "");
GUI.backgroundColor = Color.white;
}
}
}
It works ok but flicker sometimes, for example if you move some other editor window, or resize hierarchy. Sometimes it flicker without reason at all. Also it's bad that I draw above hierarchy elements not below them. There should be a better way. Thank you!
Comment