Search Unity

Layering 2D Graphics

Discussion in 'Immediate Mode GUI (IMGUI)' started by launchpad, Oct 17, 2007.

  1. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Hi All,
    I have looked, but can't see!

    Is there a way of layering (ordering) 2D graphics used as part of the new GUI calls.

    I would like to be able to dynamically change which graphic is on top.

    Thanks, Peter
     
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    In the new system, GUI elements are draw in the order they appear in your script: so the elements (windows, graphics, etc.) appearing at the top of your script are underneath and the elements at the bottom of your script are on top.

    Besides that, if you make a window moveable, then give it focus (by clicking on it) it will be displayed on top. I'm not sure how (or if) this can be done through script though.
     
  3. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    And just in case there was any confusion, all GUI class stuff is rendered on top of all the regular stuff drawn by the in-scene cameras (including their GUI Layer). So if you have a custom cursor ingame, it will go back the plain pointer when you are over GUI windows.

    And yes, there's a window focus function to change window focus under script control (you need to use it if you open a child window from a parent window, for example).
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Don't forget, you can also set GUI.depth to control the layering when you have GUI calls coming from multiple scripts.

    GUI.depth
     
  5. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    You mean the stacking of GUI class elements, right? That still doesn't layer them with things rendered by the camera, no?
     
  6. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    If you have OnGUI functions being called in different scripts, GUI.depth controls their layering among each other. None of this allows GUI elements to layer with in-scene content as all GUI stuff is drawn on top.
     
  7. DocSWAB

    DocSWAB

    Joined:
    Aug 28, 2006
    Posts:
    615
    As I thought -- thanks for the further clarification, Tom.
     
  8. launchpad

    launchpad

    Joined:
    Aug 17, 2007
    Posts:
    95
    Thanks everyone.
    The GUI.depth sounds what I am after. I am wanting to ensure that my menu buttons are always on top, even when the interface changes.
    Peter
     
  9. thylaxene

    thylaxene

    Joined:
    Oct 10, 2005
    Posts:
    716
    silly question. but what range of numbers does GUI.depth look for? I set mine between 10 and 100 and it still isn't drawn above the other gui elements being called by other scripts in OnGUI.

    [edited] OK found it out for myself... went against logic (to me anyway) and used -1. Now my element is above all others. Might be nice to mention that in the documentation....

    Cheers.