Search Unity

could I control the GUI.DragWindow range?

Discussion in 'Scripting' started by Alex Cruba, Sep 12, 2013.

  1. Alex Cruba

    Alex Cruba

    Joined:
    Aug 16, 2011
    Posts:
    564
    Hi all!

    I've a whole screen menue, but with a menu left sided. The menubutton opens a new window in the wholescreen window.

    The new window is draggable, but for sure it would be nice to force it not to overlay with the menue or topscreen discription.

    Could I define a zone or something like that?
     
  2. MaxRoetzler

    MaxRoetzler

    Joined:
    Jan 3, 2010
    Posts:
    136
    Using the DragWindow example from the scripting reference. Just modify the coordinates in the GUI update after they are set.

    There's probably a nicer way constrain the position. Haven't really done anything with gui windows :)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class Test : MonoBehaviour {
    6.     public Rect windowRect = new Rect(20, 20, 120, 50);
    7.  
    8.     void OnGUI()
    9.     {
    10.         windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    11.         // constrain the window rect x / y
    12.         windowRect.x = Mathf.Clamp(windowRect.x, 0, 300);
    13.         windowRect.y = Mathf.Clamp(windowRect.y, 0, 500);
    14.     }
    15.  
    16.     void DoMyWindow(int windowID)
    17.     {
    18.         GUI.DragWindow(new Rect(0, 0, 10000, 20));
    19.     }
    20. }
    21.  
     
  3. Alex Cruba

    Alex Cruba

    Joined:
    Aug 16, 2011
    Posts:
    564
    At last an answer... Ty bro... I'll try out tomorrow! ;)