Search Unity

Mixing GUI and GUITexture?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Foxxis, Nov 8, 2007.

  1. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    I can't seem to force a new GUI component I have written to display behind my cursor (which uses the old GUITexture component). Setting GUI.depth seems to only affect multiple GUI-derived objects, and setting the z value of the GUITexture doesn't help either.

    Granted, rewriting the cursor code takes 5 minutes, but there are other - far more complex - things that this would affect as well. I'd rather not rewrite the stuff if I can avoid it.

    So, how (if at all) can I layer GUITextures and new GUI displays in a reliable fashion...?

    Many thanks in advance!
    Dan
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    They don't mix very well. The new GUI stuff is always on top of your old stuff, and mouse events get sent to your 2.0 GUI stuff as well as the old GUITexture/GUIText stuff below it.

    I don't think there are any workarounds, but I sure would like to hear them, as this rigidity isn't well... flexible enough for my purposes. :)

    Cheers,
    -Jon
     
  3. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Basically, the old GUIText GUITexture objects are being phased out. They are included and fully functional for Unity2.x, but will eventually go away.

    You really should use the new GUI system :) If there's some critical features missing from it, file some bugs ;-)

    From the next release, mouse events do not go through the new GUI to the old GUI behind it or to scene objects
     
  4. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Sure, I know.
    However, I bet there are more projects than the one I am working on that will be transitioning from the old system to the new. So, a couple of points I would like to make:

    - I assume you are not planning on dropping the old system anytime soon? Forcing people to rewrite code simply because they upgrade is a less than ideal practice to say the least. ;)

    - When updating projects to (eventually fully) take advantage of the new system, it is probably common to need to mix the two systems as the transition happens.

    - In the future it would be very valuable if you took transitioning into account when implementing new features to replace old ones. Most people can't simply do a hard switch.

    So, back to the original question. How can I force objects created using the new system to display behind oldstyle objects? Is it possible?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Ack. It's not so much that the new GUI system has any critical bugs (that haven't already been fixed), and it's far superior for a lot of things, but sometimes I find that using GUIText/GUITexture is a faster, easier, and perfectly acceptable way to accomplish simple tasks, especially for resolution-independent graphics.

    --Eric
     
  6. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    ditto :D

    I, for one, would like to see some vestige of the old GUI system remain in the future.
     
  7. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    I think they said that sometime in the future there will be a graphical interface for creating and placing new GUI stuff. I'd assume that once they have that finished, the old GUI stuff will go away.
     
  8. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    I agree. But now the current question is whether there is some way for the two systems to work besides each other.

    I have a modular GUI where a number of different modules sometime display together. I would like to upgrade one of those (for a number of reasons).

    Thus the original question, can I force the z ordering?
     
  9. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    No, the new GUI elements will always render on top of your GUIText and GUITextures.


    We're not going to full on pull the plug on the old GUI stuff as we'll want new player versions to support old content, it's just that going forward we most definitely want folks to migrate to using the new system. Sorry, that will eventually mean you will all need to eventually stop using GUIText and GUITextures, but we're trying to avoid a "light switch" situation where you wake up one day and all of a sudden have to write new code. You've upgrade to 2.0 already, both the new and old GUI tools are there today, we did that so y'all can start your migration now so the change from old-to-new GUI systems isn't an overnight affair.

    Also, we definitely hear your statements that it's easier for you to use GUIText and GUITextures in some cases, please know that we're working on that by planning continued improvements to the new system (functional and ease-of-use improvements). With those improvements and you getting more comfortable with the new GUI tools we expect folks will eventually find the new system both easier and more powerful.
     
  10. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Thanks for the answer!

    I personally absolutely love the new system, so the question wasn't born out of not wanting to use it for whatever reason. It's simply the case that mixing them would have made the transition period easier on this project.

    Now I'll have to drop some other things and dedicate some time to rewriting more stuff than planned. In the end, it will probably result in a better product, but right now it's annoying.

    Anyway, in the future, please pay a little bit more attention to how a transition between new/old versions of systems will affect developers. ;)
     
  11. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Besides being easier, there -are- situations where I would want my gui element to be lower in z order than every other gui element. For example, I am using the old GUIText to create a "heads up" numeric display, that remains behind pop-up windows that are created with the new GUI system. I am also using GUITexture as a graphic overlay in a pop up window created with the new GUI system.
     
  12. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    That's exactly what I need to do. The graphic overlay was already done, and I decided to recode the window using the new system. Did you actually find a way to pull that off..?
     
  13. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    My set up may have been a bit different than what you want to do (and I haven't tested this since the last 2.0 Beta) but I was using the GUITexture overlay on a Render to texture that was in a GUI window. That seemed to work the last time I tested it. My beta test machine crashed recently so I'll have to pull out my backup to confirm that this still works with 2.0.1 final (which is on my "to do" list for today/tomorrow).
     
  14. JohnyZuper

    JohnyZuper

    Joined:
    Jan 7, 2008
    Posts:
    174
    I'm missing the ability to scale the text relative to the size of the window. The ability to turn off "Pixel Correct" is one of the main reasons for me to use GUIText.
     
  15. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    I'm missing the ability to scale the text relative to the size of the window.

    I think you can use a matrix4x4 to accomplish this
     
  16. JohnyZuper

    JohnyZuper

    Joined:
    Jan 7, 2008
    Posts:
    174
    :eek:
    How?
    (sorry: newbie here)
     
  17. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    Code (csharp):
    1. var pos = new Vector3(0,0,0);
    2. var q =  Quaternion(0,0,0,1);
    3. var s = new Vector3(2,2,2);//adjust scale here
    4. var tMatrix : Matrix4x4 = Matrix4x4.TRS(pos, q, s);
    5. GUI.matrix = tMatrix;//this adjusts everything below
    6.  
    7. GUI.Label(Rect(0,0,100,100),"bhlasdhasdhf");
    8.  
    9.  
    10. //back to normal
    11. pos = Vector3(0,0,0);
    12. q =  Quaternion(0,0,0,1);
    13. s = Vector3(1,1,1);//adjust scale here
    14. tMatrix = Matrix4x4.TRS(pos, q, s);
    15. GUI.matrix = tMatrix;
     
  18. JohnyZuper

    JohnyZuper

    Joined:
    Jan 7, 2008
    Posts:
    174
    Thanks.

    I guess the "s" vector should get values that express the aspect ratio of the window...