Search Unity

Setting depth of a Window

Discussion in 'Immediate Mode GUI (IMGUI)' started by benblo, Aug 8, 2008.

  1. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    I have a simple script for mouse cursor replacement, set at depth 0.
    All my other GUI scripts are at higher depth.

    But unfortunately, windows are still drawn on top of my cursor... setting a high depth before GUI.Window or inside the window function has no effect.

    ... any ideas?
     
  2. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    If your mouse replacement is done via OnGUI(), then it will always appear behind all GUI.Window calls.
     
  3. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Damn, I was afraid of that... it sucks!
    So that means I have to use an ancient GUIText, like the wiki script, right?
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    OnGUI is always drawn on top of everything, including GUITextures. I think some kind of custom cursor function is necessary, where it's not covered by anything.

    --Eric
     
  5. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    I have an ingame console that blacks out the entire screen by a function like this:
    Code (csharp):
    1.  
    2. function OnGUI()
    3. {
    4.     if( !isEnabled )
    5.         return;
    6.    
    7.     GUI.depth = -255;
    8.    
    9.     GUILayout.BeginArea( Rect(0,0,Screen.width,Screen.height), "", "box" );
    10.  
    11. ...
    12.  
    13.     GUILayout.EndArea();
    14. }
    The entire screen (including all my gui windows) gets blacked out nicely. As a side bonus, I can still click through the black box to interact with those windows.

    Haven't done any testing, but I am sure you could just make a custom cursor style and apply it instead of "box".
     
  6. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Cool, didn't think of that :) As far as I know, setting GUI.Depth to anything less than 1 will draw it over GUI.Windows. Interestingly the documentation doesn't mention the overlap between OnGUI and GUI.Window depths.
     
  7. benblo

    benblo

    Joined:
    Aug 14, 2007
    Posts:
    476
    Thanks guys... this depth thing sure is obscure and ill-documented!
    I thought negative depth had no effect, I even filed a bug about this when 2.0 came out, maybe they changed it?
    I sure wish they'd used the more traditional z-index convention... but if depth can be negative after all, the result is the same, so that's cool :)


    I don't really understand that... you said earlier:
    ... which is it?


    Anyway, it turns out I didn't explicitly set GUI.depth in my mouse cursor script, assuming it would be 0 by default... but in fact, it seems that GUI.depth isn't reset between scripts, so my cursor used the depth set by the last running script!
    Now I'm setting it to 0 explicitly and my cursor does appear on top of my windows.


    I'm filing a bug asking for clarification... let's all file one to keep the pressure up ;)
     
  8. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    @Ben
    So by default, everything you put in OnGUI renders behind windows, unless you specify a GUI.depth of less than 1, and then the controls immediately after the depth setting will appear over your windows. Sorry about the ambiguity.