- Home /
OnGUI draw order issue
I have an editor window that draws a dynamic tree hierarchy, where each node is a GUI.Box, after that in the code I draw the connecting accordion lines. As you can see the lines are drawn in front of the tiles. This is happening in a single script. I moved the drawing of the tiles after the drawing of the lines, but it didnt work. I tried GUI.depth, didnt work.
Edit: What Im doing in code is:
foreach(allTiles) {
if(something) {
drawConnectinglines()
}
drawTileAndItsContent
}
Now Itried seperating the tile draw and line draw in different loops:
foreach(allTiles) {
if(something) {
drawConnectinglines()
}
}
foreach(allTiles) {
drawTileAndItsContent
}
The result is that now the lines are behind the buttons in the tiles, but infront of them:
GUI.depth only works between scripts, not inside the same script.
If the buttons and tiles should be drawn later (over) the lines, call their drawing code after the line drawing code.
Do you use EditorGUI functions for all the drawing?
$$anonymous$$y setup is: EditorGUILayout.BeginScrollView GUILayout.Box with size calculated from all tiles - makes the scrollview to actually "scroll" Tiles, Lines and buttons use GUI.box/button end scrollview
Answer by Garazbolg · Jan 25, 2016 at 02:07 PM
First of all : we need more information then that to help you. Second : changing the order should have done the trick but i can't tell why it didn't (not enough informations) Finally : i think you should draw every child of each branch before going to the next like this :
Root
|
+----A
| |
| + ------A1
| | |
| | +-----A1a
| | |
| | +-----A1b
| | |
| | +-----A1c
| |
| +-------A2
| | |
| | +-----A2a
| |
| +-------A3
|
+----B
|
+ ------B1
|
+-----B1a
|
+-----B1b
Like this you shouldn't have anything overlapping. And you can use recusivity to display that tree.
Hope it helps you, but if you want more you'll have to give us more to work with.
Ive updated my question, hope it makes it a little more clear.
Its better but your problem isn't really there. I think the problem is in the way you draw the lines, because shouldn't "Stats Summury" come from "Stats" ins$$anonymous$$d of "Robot" ?
If that's right then "Robot" should have only one child and the line should stop at point where it goes to "Build Robot"
$$anonymous$$aybe show your code ( the real one not some pseudo code) from drawConnectingLines() ? It would be way easier to spot what is wrong.
Oh dang, I got it. Yes you are right - stats summary and build robot are on the same level(indentation) and what I do is I draw from the last to the first tile on the level, which doesnt take into account if the tiles have different parent. I guess I should draw the line not to the first panel on the level but to the first panel with the same parent on the level. Thanks, well see if that works.
Uhm, no, ^^ it's not really clearer. It seems you messed up your line drawing. Some lines should have ended earlier. It seems your structure should look like this:
$$anonymous$$ain $$anonymous$$enu
|
+--Robot
| |
| \--Build Robot
| |
| \--Build Robot Inventory
| |
| \--Build Robot Item Details
|
+--Stats
| |
| +--Stats Summary
| |
| +--Stats Statistics
| |
| +--Stats Achievements Select
| | |
| | \--Stats Achievement
| |
| \--Stats Ladder
| |
| \--Stats All Ladders
|
\--Social $$anonymous$$enu
It might go further down after "Social $$anonymous$$enu" but we don't see more than that. As you can see "Robot" has only one child object which is "Build Robot". So the vertical line that starts at "Robot" should end at "Build Robot". The same holds true for deeper childs as well.
We don't know how you draw those lines but you most likely have a logic error there.