Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Dynamic, centered canvas in GUIX?

Discussion in 'External Tools' started by WarpZone, Oct 5, 2009.

  1. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    320
    Hey I just checked out GUIX. It looks really cool and useful and I will probably end up buying it.

    There's just one problem. The default example makes a menu which is ideal for the web player but when you resize the window it just sticks in the upper-left corner of the screen. How can I make it so it is always centered and it resizes the whole thing to fill the screen?

    It seems silly to go to all that trouble to allow this for buttons and images and then to drop the ball with the canvas itself. :(

    If there is a way to turn a static canvas into a full-screen canvas using GUI.matrix, please provide example code on how to do this. The Unity scripting reference is horribly brief about GUI.Matrix. :/

    If you can't resize it, is there a way to at least keep it centered when the window is resized?

    Thanks in advance. Especially to the good people behind GUIX. It looks like a great tool, I just don't get how to make it do what I *really* want. (I.E. Full-screen menus that look more or less the same on all platforms and at all resolutions.)

    Thanks again. :D
     
  2. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    320
    Nevermind, I figured out a way to do it.

    It was super-easy, too. The Canvas object has a rectangle called Rect and this is actually completely accessible. The example implementation actually sets the x and y offsets when the script first runs.

    Code (csharp):
    1.  
    2.     _myCanvas = new SampleCanvas();
    3.     _myCanvas.Rect.x = 20.0;
    4.     _myCanvas.Rect.y = 20.0;
    5.  
    So it turns out I can just set the height and width of that rectangle to the screen's height and width every GUIUpdate!

    Code (csharp):
    1.  
    2. function OnGUI ()
    3. {
    4.     _myCanvas.Rect.width = Screen.width;
    5.     _myCanvas.Rect.height = Screen.height;
    6.     _myCanvas.Draw();      
    7. }
    8.  
    I'm sure doing it this way wastes a little processing power. How much waste remains to be seen. I guess I can probably save some by comparing the width this GUI update to the width last GUI update, and only changing the Canvas if the screen size has changed.

    But this is definitely the missing feature I so badly needed. Finally I can make full-screen interfaces that *just work,* no matter what the end-user's screen looks like.

    I will definitely be picking up a copy of GUIX now, and using it religiously right up until I decide it's time to make an iphone game. :p
     
  3. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    You got it. ;-)

    You don't need to worry about the speed of that at all, due to the way the processing is done internally. It is designed to be set "on the fly" as you need.

    I'll see about cleaning up the docs to make this more clear also.

    Take care!
    -Jeremy