Search Unity

Aspect-ratio scale

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

  1. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    - Let's say you design your interface coordinates for 1920x1200, as the Lerpz tutorial suggests. Then, you scale it as the tutorial says like this:

    GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3
    (Screen.width / 1920.0, Screen.height / 1200.0, 1));


    My question is, how do you do it when the aspect ratio changes?

    Also, I would like to ask something I have been looking for a few days and I haven't found. I have a texture with a lot of GUI elements in it, how do I render them separately? More specifically, where do I specify the UV coords inside the texture for the GUI.Box, for example?
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    You have a few options...
    • Many games just stretch-to-fill to the screen - aspect ratio be damned,
    • Many games just stretch-to-fit so that the GUI can fit in a (typically centered) square on-screen.

    You slice up the texture in photoshop, then draw that.
    Take a look here for some GUI skins for inspiration:
    http://unity3d.com/support/resources/assets/extra-gui-skins
    http://unity3d.com/support/resources/assets/built-in-gui-skin

    Have fun!
     
  3. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    I see, slicing in photoshop and having a texture for every element...

    But what if I really need to draw just a region of the texture? For example, I have a top view of a navigation map, the texture for the map is 2048x2048 and I only want to draw the 512x512 region where the player is, centered on the player... how would I do it?
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    You would use a BeginGroup..EndGroup to set up a clipping rect, then slide your texture around inside that.
     
  5. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    Contrieved. ;) ;) ;)

    Seriously, I really think that the system would be far better with UV support, there are a gazillion things in which you need them, the map is just an example... another example would be a digital compass, or the altimeter (I'm doing an airplane game, is it obvious? :) ) what do you think?
     
  6. JohnGalt

    JohnGalt

    Joined:
    Nov 27, 2007
    Posts:
    85
    Nicholas,

    I have finally implemented it using the BeginGroup method and in the end I don't find it that painful, in fact, it's probably even better than having to set texture coords in the classical way (u = coordX/Texture.width;).

    The only problem is probably that inside is more expensive in performace, because the BeginGroup/EndGroup system???