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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

GUILayout Problem

Discussion in 'Immediate Mode GUI (IMGUI)' started by Gilead7, May 27, 2009.

  1. Gilead7

    Gilead7

    Joined:
    Apr 2, 2009
    Posts:
    27
    I'm not sure how to do this or if it is even possible.
    I have a Gui Layout so that all elements inside the box can remain inside the box.

    What I want to do is to position the elements inside the box, like moving the icon image over or setting the text next to it, but I need to keep in mind the screen resolutions people will be using for the game.
    The alignment I'm looking for is image then text next to it on the right with selected buttons below for a choice.
    Any thoughts?
    Don't mind my label ramblings...
    This is what I have so far:

    var image : Texture2D;
    function OnGUI () {
    GUILayout.BeginArea (Rect (Screen.width/2, Screen.height/2, Screen.width-50,Screen.height-50),"Testing Menu");

    GUILayout.Button (image);
    GUILayout.Label ("Text Description Goes Here: What shall I say, I guess the real question is just how much space can I take up while still keeping the sentences as I envisioned them. What do you think about that? So that means that I can write some very long explanation and as long as I set the parameters to match, everything should be very readable, very descriptive and very informative. I will have no limits on the amount of text needed to get the point across. Right?");
    GUILayout.EndArea();
    }
     
  2. DrHotbunz

    DrHotbunz

    Joined:
    Feb 14, 2009
    Posts:
    315
    One idea is to use GUIStyles with your GUILayout controls and turn off stretch width and height. Then set a fixed height and width the same as your image.

    Then reference each control from the center of the screen.

    Note: PTtexture is a GUIStyle, PT_texture is a 2Dtexture and selectPT is a boolean.


    Code (csharp):
    1. GUILayout.BeginArea (Rect (Screen.width/2-adjustright_PT, Screen.height/2-adjustup_PT,468,192));
    2.                            if(GUILayout.Toggle (selectPT, PT_texture, PTtexture )){
    3. closewindow=true;
    4. }
    5. GUILayout.EndArea();

    This is not a perfect solution. However it is very workable and everything ends up pixel perfect and wont move with resolution.
     
  3. Gilead7

    Gilead7

    Joined:
    Apr 2, 2009
    Posts:
    27
    What do I define adjustright_PT and adjustup_PT or are they the "try some numbers here to see how they look."
     
  4. DrHotbunz

    DrHotbunz

    Joined:
    Feb 14, 2009
    Posts:
    315
    When running the game use the inspector to adjust adjustright_PT and adjustup_PT in real time. Normally I drag my mouse to set them. This moves the GUI around the game and I get everything set right.

    Then when your happy stop the game and type the new values into the inspector.

    This is all you have to do, you never have to recode adjustright_PT and adjustup_P Unity will remember these values forever. Great way to adjust stuff in real time.