首页 > 代码库 > Unity3d GUI弹窗
Unity3d GUI弹窗
ArrayList w_position = new ArrayList();
void OnGUI()
{
if (GUILayout.Button("Open"))
{
if (allowMove)
{
allowMove = false;
}
w_position.Add(new Rect(200 + w_position.Count * 40, 200 + w_position.Count * 50, 100, 200));
}
for (int i = 0; i < w_position.Count; i++)
{
//创建弹窗
w_position[i] = GUILayout.Window(i, (Rect)w_position[i], OpenWindow, "window");
}
}
void OpenWindow(int windowID)
{
if (GUILayout.Button("close"))
{
allowMove = true;
w_position.RemoveAt(windowID);
}
//允许拖拽窗口,如果去掉,窗口位置固定
GUI.DragWindow(new Rect(0, 0, 10000, 500));
}
把GUILayout.Window 改为 GUI.ModalWindow,可以实现弹模态窗口
Unity3d GUI弹窗