Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

[SOLVED]Positioning a GuiTexture

Discussion in 'Immediate Mode GUI (IMGUI)' started by BigB, Aug 10, 2009.

  1. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    670
    Hi,

    I'm having a hard time, tryng to understand how to get this working correctly.
    I have a texture, of size 697x188, and i want to place this texture on the bottom right corner.
    Although i got this working, once i change resolution, the gui texture also changes position.
    I have it setup like this :

    Pixel Inset
    x = 0
    y = 0
    width = 697
    height = 188

    The borders all at zero
    Position at zero

    And in a script, on the Start function, i do the following :

    transform.position.y = -0.007;
    transform.position.x = 0.48;

    How can i make this work ? Is there some example somewhere, on how to make the gui screen resolution independent ?

    thanks,
    Bruno
     
  2. TheAlchemist42

    TheAlchemist42

    Joined:
    Apr 17, 2008
    Posts:
    68
  3. BigB

    BigB

    Joined:
    Oct 16, 2008
    Posts:
    670
    Thanks for the link.
    However, i already spotted this, and i still can't get this to work, the Matrix is simply ignored.

    I have it this way, on the OnGui function :

    GUI.matrix = Matrix4x4.TRS(transform.position,Quaternion.identity,Vector3((Screen.width / nativeHeight,(Screen.height / nativeHeight), 1.0));

    Replacing transform.position does nothing either.

    But my problem is the gui positioning, not the gui scaling, and as i see this is just for scaling.
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Use of GUI matrices is for UnityGUI, not GUIText/GUITextures. As to your problem, you can try setting the transform.position values or manipulate the pixel inset values only (put object at 0,0,0). In either case you might need to monitor the screen size and at run-time make the necessary adjustments to keep the various elements where you want them.
     
  5. DrHotbunz

    DrHotbunz

    Joined:
    Feb 14, 2009
    Posts:
    315
    This is the way I do it.

    Very simple and straightforward, and works with all resolutions. I use something like the code below, then adjust the adjustx and the adjusty to move the texture (which is referenced through the GUIstyle) wherever i want on screen (even the bottoom corner) (and then I stop the game and re-enter the numbers the asjustx and the adjusty in the inspector and re-save the scene) and it stays there for all resolutions, even in the bottom corner.

    The texture in this case is 105 by 105 pixels and stretch in the GUIstyle is off.

    Code (csharp):
    1. var adjustx21 : float;
    2. var TTF_GUI : GUIStyle;
    3. //********************
    4. GUILayout.BeginArea(Rect(Screen.width*adjustx21-105,Screen.height*adjusty21-105,Screen.width,Screen.height));
    5.   GUILayout.BeginHorizontal();
    6.      GUILayout.Button ("",texture_GUI)
    7.   GUILayout.EndHorizontal();
    8. GUILayout.EndArea();
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,355
    I make everything resolution-independent: ditch all the pixel inset stuff, and make the x scale (for example) .2 and the y scale .1. Then, to always be in the lower-right, the x position would be .9 and the y position would be .05. Done. :) Works with all resolutions, uses no scripting.

    --Eric
     
  7. DrHotbunz

    DrHotbunz

    Joined:
    Feb 14, 2009
    Posts:
    315
    wheres the fun in that ?
     
  8. fis

    fis

    Joined:
    Sep 16, 2009
    Posts:
    25
    to Eric5h5
    yes, it works for standalone app. But I have troubles in the window mode in web player - my logo got out the window. But when I run fullscreen mode - it works fine
     

    Attached Files:

  9. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,355
    Did you change all the pixel inset values to 0, and use the normal position and scale values only? I have no issues with any size window or screen when doing that, including the web player.

    --Eric
     
  10. fis

    fis

    Joined:
    Sep 16, 2009
    Posts:
    25
    Some screenshots
    - full screen mode (1920x1200) in web player
    - settings
    - full screen mode (1920x1200) in standalone
    P.S
    and I noticed that logo is out of the screen also in the stand alone app when I decrease resolution
     

    Attached Files:

  11. fis

    fis

    Joined:
    Sep 16, 2009
    Posts:
    25
    Haa!! I have found working parameters.
    X axis position should be 1 (for bottom right corner) but X of Pixel inset shoud be the same as image Width but with opposite sign.

    So now everithing is Ok with all resolutions and all players. 8)
     

    Attached Files:

  12. fdfragoso

    fdfragoso

    Joined:
    Nov 15, 2010
    Posts:
    35
    @HiggyB - I understand that the way "manual"you said would be done as follows, if I want the application has 1024x768 I'll have to manually make the positioning of GUI and so on, but when it is full screen as I proceed?

    Thanks,
    FDF
     
  13. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    well, with scripting, you can do this, just use
    Code (csharp):
    1. Screen.width - texture.width - 10
    ect (this is in the OnGUI function, but I assume you can do this in any function, just change it a little)