UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
GUILayout.Window
# [GUILayout](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.html).Window public static [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **Window** (int **id**, [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **screenRect**, [GUI.WindowFunction](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUI.WindowFunction.html) **func**, string **text**, params GUILayoutOption[] **options**); public static [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **Window** (int **id**, [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **screenRect**, [GUI.WindowFunction](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUI.WindowFunction.html) **func**, [Texture](https://docs.unity3d.com/cn/2019.4/ScriptReference/Texture.html) **image**, params GUILayoutOption[] **options**); public static [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **Window** (int **id**, [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **screenRect**, [GUI.WindowFunction](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUI.WindowFunction.html) **func**, [GUIContent](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUIContent.html) **content**, params GUILayoutOption[] **options**); public static [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **Window** (int **id**, [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **screenRect**, [GUI.WindowFunction](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUI.WindowFunction.html) **func**, string **text**, [GUIStyle](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUIStyle.html) **style**, params GUILayoutOption[] **options**); public static [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **Window** (int **id**, [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **screenRect**, [GUI.WindowFunction](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUI.WindowFunction.html) **func**, [Texture](https://docs.unity3d.com/cn/2019.4/ScriptReference/Texture.html) **image**, [GUIStyle](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUIStyle.html) **style**, params GUILayoutOption[] **options**); public static [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **Window** (int **id**, [Rect](https://docs.unity3d.com/cn/2019.4/ScriptReference/Rect.html) **screenRect**, [GUI.WindowFunction](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUI.WindowFunction.html) **func**, [GUIContent](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUIContent.html) **content**, [GUIStyle](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUIStyle.html) **style**, params GUILayoutOption[] **options**); ## 参数 | id | 用于每个窗口的唯一 ID。您将使用该 ID 与其进行交互。 | | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | screenRect | 屏幕上用于窗口的矩形。布局系统会尝试将窗口适配到其内部 - 如果无法完成,则调整矩形以进行适配。 | | func | 在窗口/内/创建 GUI 的函数。该函数必须接收一个参数 - 要为其创建 GUI 的窗口的 /id/。 | | text | 要显示为窗口标题的文本。 | | image | 在标题栏中显示图像的 [Texture](https://docs.unity3d.com/cn/2019.4/ScriptReference/Texture.html)。 | | content | 该窗口的文本、图像和工具提示。 | | style | (可选)用于窗口的样式。如果省略,则使用当前 [GUISkin](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUISkin.html) 的 `window` 样式。 | | options | (可选)一个布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 `style` 或您传入的 `screenRect` 定义的设置。另请参阅:[GUILayout.Width](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.Width.html)、[GUILayout.Height](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.Height.html)、[GUILayout.MinWidth](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.MinWidth.html)、[GUILayout.MaxWidth](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.MaxWidth.html)、[GUILayout.MinHeight](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.MinHeight.html)、 [GUILayout.MaxHeight](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.MaxHeight.html)、[GUILayout.ExpandWidth](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.ExpandWidth.html)、[GUILayout.ExpandHeight](https://docs.unity3d.com/cn/2019.4/ScriptReference/GUILayout.ExpandHeight.html)。 | ## 返回 **Rect** 窗口所在的矩形。其位置和大小可以与您传入的矩形不同。 ## 描述 创建一个对自身内容进行自动布局的弹出窗口。 窗口浮动在普通 GUI 控件上方,可通过点击获得焦点,可以选择是否允许最终用户拖动。 与其他控件不同,您需要为它们传递一个将 GUI 控件放置在窗口内的独立函数。下面是一个帮您入门的小示例:  \ *游戏视图中的窗口。* ``` using UnityEngine; public class ExampleScript : MonoBehaviour { Rect windowRect = new Rect(20, 20, 120, 50); void OnGUI() { // Register the window. Notice the 3rd parameter windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window"); } // Make the contents of the window void DoMyWindow(int windowID) { // This button will size to fit the window if (GUILayout.Button("Hello World")) { print("Got a click"); } } } ``` 您传入该函数的屏幕矩形仅用作指导。要对窗口应用额外限制,请传入一些额外的布局选项。在此应用的选项将覆盖计算出的大小。下面是一个小示例: ``` using UnityEngine; public class ExampleScript : MonoBehaviour { Rect windowRect = new Rect(20, 20, 120, 50); void OnGUI() { // Register the window. Here we instruct the layout system to // make the window 100 pixels wide no matter what. windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100)); } // Make the contents of the window void DoMyWindow(int windowID) { // This button is too large to fit the window // Normally, the window would have been expanded to fit the button, but due to // the GUILayout.Width call above the window will only ever be 100 pixels wide if (GUILayout.Button("Please click me a lot")) { print("Got a click"); } } } ```
da
2022年6月10日 00:19
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码