标题 | 对话框的标题。 |
消息 | 对话框的目的。 |
确定 | 选择对话框功能。 |
取消 | 关闭对话框而不执行任何操作。 |
其他 | 选择其他对话框目的。 |
int 返回按钮的 ID。ID 为 0、1 或 2,分别对应于 ok
、cancel
和 alt
按钮。ID 为 1,对应于 cancel
,在关闭对话时或用户按 Escape 键时返回。
显示带三个按钮的模态对话框。
在编辑器中显示消息框时使用它。DisplayDialogComplex
类似于 DisplayDialog。此 DisplayDialogComplex
成员显示一个带三个按钮的对话框。这些按钮表示 ok
、cancel
和 alt
。 DisplayDialogComplex
返回整数 0、1 或 2,分别对应于 ok
、cancel
和 alt
按钮。ok
按钮是默认选项,也可以通过按 Enter 键激活。cancel
按钮被视为“取消”按钮,通常不应执行任何操作。在 PC 上,也可以通过按 Escape 键或单击对话框窗口关闭按钮来激活此按钮。在 Mac 上,如果按钮名为“取消”,也可以通过按 Escape 键来激活此按钮。alt
按钮允许你除了提供 ok
和 cancel
按钮外,为用户提供其他选择。此按钮没有固定的键盘快捷键。
为了符合平台界面的指南,按钮的实际显示顺序从属于平台
ok
、alt
,然后是 cancel
。alt
、cancel
,然后是 ok
。其他资源:DisplayDialog。
以下示例的 macOS 显示对话框按钮。
以下示例的 PC 显示对话框按钮。
以下脚本参考示例创建了一个复杂的显示对话框。所选按钮会导致调用一个 Unity EditorApplication 静态函数。
using UnityEngine; using UnityEditor;
public class DisplayDlgComplexExample : EditorWindow { // Lets you save or not before quitting, or cancel.
[MenuItem("Example/Quit")] static void Init() { int option = EditorUtility.DisplayDialogComplex("Unsaved Changes", "Do you want to save the changes you made before quitting?", "Save", "Cancel", "Don't Save");
switch (option) { // Save. case 0: EditorApplication.SaveScene(EditorApplication.currentScene); EditorApplication.Exit(0); break;
// Cancel. case 1: break;
// Don't Save. case 2: EditorApplication.Exit(0); break;
default: Debug.LogError("Unrecognized option."); break; } } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.