Apparently there are no GUILayout.DragWindow() as opposed to GUI object.
Is there a way to enable GUILayout.Window() to be dragged?
Apparently there are no GUILayout.DragWindow() as opposed to GUI object.
Is there a way to enable GUILayout.Window() to be dragged?
Just use GUI.DragWindow() it works despite the name.
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!!