Search Unity

GUI.Window Problem

Discussion in 'Scripting' started by mbahadirb, Jan 5, 2011.

  1. mbahadirb

    mbahadirb

    Joined:
    Jul 8, 2010
    Posts:
    21
    Hi

    I don't know if there is a problem with GUI.Window or totaly my mistake when I want to create a window using the code below I always get the same window( same size/place - not where orhow it should be ).

    Code (csharp):
    1.  
    2. var windowRect : Rect = Rect( 100, 100, 100, 200);
    3.  
    4. function OnGUI(){
    5.     windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
    6. }
    7.  
    8. function DoMyWindow (windowID : int) {
    9. GUI.DragWindow (Rect (0,0,10000,10000));
    10.     if (GUI.Button (Rect (10,20,100,20), "Hello World"))
    11.         print ("Got a click in window " + windowID);
    12.     if (GUI.Button (Rect (10,40,100,20), "Hello World"))
    13.         print ("Got a click in window " + windowID);
    14.        
    15.    
    16. }
    17.  
    18.  
    When I made the change below it-as it should- became un-draggable:

    Code (csharp):
    1.  
    2. windowRect = GUI.Window (0, Rect( 100, 100, 200, 200 ), DoMyWindow, "My Window");
    3.  
    I just want a draggable big window with lots of stuff in it pls:(
     
  2. juan_txo

    juan_txo

    Joined:
    Sep 6, 2010
    Posts:
    11
    Good Morning, with the code below in c# it works perfectly here you have the JavaScript lines. if you put the method "GUI.DragWindow ();" at the end the whole window you make will be draggable and you can never drag the window from outside it.


    function DoMyWindow (windowID : int) {
    GUI.Button (Rect (10,20,100,20), "Can't drag me");
    GUI.DragWindow ();
    }


    If it doesn´t works here iam.
     
  3. mbahadirb

    mbahadirb

    Joined:
    Jul 8, 2010
    Posts:
    21
    i did that didnt work:D


    my problem is with size and place
     
  4. juan_txo

    juan_txo

    Joined:
    Sep 6, 2010
    Posts:
    11
    if you put this method GUI.DragWindow (); it gets the window size and its works, i tested in c# and works ok
     
  5. mbahadirb

    mbahadirb

    Joined:
    Jul 8, 2010
    Posts:
    21
    ok thanks a lot
     
  6. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    Huh I tried write a simple unity scene with a simple javascript and it doens't work as well!

    Here my code:

    Code (csharp):
    1.  
    2.  
    3. function OnGUI()
    4. {
    5.     var windowRect0 = Rect( 15, 100, 600, 200);
    6.     var windowRect1 = Rect( 150, 100, 600, 400);
    7.  
    8.     windowRect1 = GUI.Window(0, windowRect1, ShowWindow2, "Good morning",GUI.skin.GetStyle("window") );
    9.     windowRect0 = GUI.Window(1, windowRect0, ShowWindow, "Good morning");
    10.  
    11.  
    12. }
    13.  
    14. function ShowWindow2(windowID : int) {
    15.    
    16.     GUI.Label( Rect( 20,75,410,60),"Hello world !!");
    17.     GUI.DragWindow();
    18. }
    19.  
    20. function ShowWindow(windowID : int) {
    21.    
    22.     GUI.Label( Rect( 20,75,410,60),"Hello world !!");
    23.     GUI.DragWindow();
    24. }
    25.  
    26.  
    Both windows are not draggable...I can focus one or the other by clicking on them, but no dragging...why ?
     
  7. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    @Litobyte: the reason the windows don't drag is that you are using local variables to store the rectangle returned from GUI.Window. The values need to persist between OnGUI calls, so you need to declare these variables outside the function.
     
  8. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    Jeez! Why didn't I find this out myself !??

    Very kind of you,
    thanks!