Note: If you are using
GUILayout to place your components inside the window, you should use GUILayout.Window. Also, if
MonoBehaviour.useGUILayout is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.
var windowRect : Rect = Rect (20, 20, 120, 50); function OnGUI () { // Register the window. Notice the 3rd parameter windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window"); } // Make the contents of the window function DoMyWindow (windowID : int) { if (GUI.Button (Rect (10,20,100,20), "Hello World")) print ("Got a click"); }
You can use the same function to create multiple windows. Just make sure that
each window has its own ID. Example:
var windowRect0 : Rect = Rect (20, 20, 120, 50); var windowRect1 : Rect = Rect (20, 100, 120, 50); function OnGUI () { // Register the window. We create two windows that use the same function // Notice that their IDs differ windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "My Window"); windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "My Window")//这里必须返回窗体的Rect,否则无法拖动窗口
} // Make the contents of the window function DoMyWindow (windowID : int) { if (GUI.Button (Rect (10,20,100,20), "Hello World")) print ("Got a click in window " + windowID); // Make the windows be draggable. GUI.DragWindow (Rect (0,0,10000,10000));//拖动窗口的代码,必须要是10000吗,反正1000不可以拖动 }