Search Unity

Z-Order

Discussion in 'Immediate Mode GUI (IMGUI)' started by JohnGalt, Jan 14, 2008.

  1. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    If there are two different scripts that draw controls in their respective OnGUI, it is not possible to specify which one gets called last. The only way to control the draw order of controls is changing the function call order inside a OnGUI, but when your GUI code is dispersed in two or three scripts, you lose control of when this OnGUIs get called.

    The only possibility then is to code a Manager which centralizes all your GUI code. You would call this manager specifying the desired Z-Order like this:

    MyManager.Label(params..., Z-Order);

    I'd like to avoid coding this manager, but this is the only solution I have.

    My concrete problem is that I have a FadeOut script that does:

    Code (csharp):
    1.  
    2. function OnGUI()
    3. {
    4.         var text2D : Texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false);
    5.         text2D.SetPixel(0, 0, Color(0, 0, 0, mCurrentParam));
    6.         text2D.Apply();
    7.        
    8.         // Need to apply a GUIStyle in order to stretch to fullscreen size the texture
    9.         var style : GUIStyle = new GUIStyle();
    10.         style.normal.background = text2D;
    11.         GUI.Label(Rect(0, 0, Screen.width, Screen.height),text2D, style);
    12. }
    13.  
    Obviously this OnGUI needs to be called last of all the others OnGUI.

    Any phylosophical or practical thoughts on this will be very appreciated ;)
     
  2. careyagimon

    careyagimon

    Joined:
    Dec 20, 2007
    Posts:
    209
    I can't test this right now, but is GUI.depth what you are looking for?
     
  3. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    That will do, somehow I missed it, thank you!!!