- Home /
GUILayout Draggable Window
Apparently there are no GUILayout.DragWindow() as opposed to GUI object.
Is there a way to enable GUILayout.Window() to be dragged?
Answer by Fattie · Sep 26, 2013 at 04:32 PM
Bizarrely, the best way to do it ........ seems to be like this:
private Rect windowRect;
void OnGUI()
{
windowRect = GUILayout.Window(0, windowRect, SomeButtons, "Title:");
}
private void TestButtons(int windowID)
{
GUILayout.BeginVertical();
if (GUILayout.Button("Explode")) yourFunction();
if (GUILayout.Button("Destroy")) yourFunction();
if (GUILayout.Button("Obliterate")) yourFunction();
if (GUILayout.Button("Crush")) yourFunction();
GUILayout.EndVertical();
GUI.DragWindow();
}
private void YourFunction() { Debug.Log("Holy crap it works."); }
Note that you just drop the GUI.DragWindow() code "magically at the end" and it works. What the hell, eh?
to set an initial position, just do this with the windowRect variable. (Or of course, set it in your "Start" - or whatever is relevant to you.)
private Rect windowRect = new Rect(0f,0.2*Screen.height,0f,0f);
Cheers!!
It doesn't work - yourFunction() should be YourFunction() (like it is below) and SomeButtons should be TestButtons or vice-versa. Otherwise excellent.
Your answer
Follow this Question
Related Questions
GUILayout formatting help 1 Answer
GUILayout Textfield not editable just static 1 Answer
Using treeview OnGUI with GUIlayout 0 Answers
How to change thickness of ScrollBar of GUILayout ScrollView? 0 Answers
button with content in multiple colors 3 Answers