Version: 2023.1
public static bool DisplayDialog (string title, string message, string ok, string cancel= "");

参数

title 消息框的名称。
message 消息的文本。
ok OK 对话框按钮上显示的标签。
cancel Cancel 对话框按钮上显示的标签。

返回

bool 如果用户单击 OK 按钮,则返回 /true/。否则返回 /false/。

描述

此方法显示模态对话框。

用于在编辑器中显示消息框。

okcancel 是对话框按钮上要显示的标签。如果 cancel 为空(默认),则仅显示 一个按钮。如果按下 ok 按钮,则 DisplayDialog 返回 /true/。

For dialog boxes that might be shown repeatedly, consider using an overload of this method that takes a DialogOptOutDecisionType as described in the below the code example.

See Also: EditorUtility.DisplayDialogComplex function.


此对话框显示的是与表面上放置的对象数量相关的信息。

// Places the selected Objects on the surface of a terrain.

using UnityEngine; using UnityEditor;

public class PlaceSelectionOnSurface : ScriptableObject { [MenuItem("Example/Place Selection On Surface")] static void CreateWizard() { Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep | SelectionMode.ExcludePrefab | SelectionMode.Editable);

if (transforms.Length > 0 && EditorUtility.DisplayDialog("Place Selection On Surface?", "Are you sure you want to place " + transforms.Length + " on the surface?", "Place", "Do Not Place")) { Undo.RecordObjects(transforms, "Place Selection On Surface"); foreach (Transform transform in transforms) { RaycastHit hit; if (Physics.Raycast(transform.position, -Vector3.up, out hit)) { transform.position = hit.point; Vector3 randomized = Random.onUnitSphere; randomized = new Vector3(randomized.x, 0F, randomized.z); transform.rotation = Quaternion.LookRotation(randomized, hit.normal); } } } } }

public static bool DisplayDialog (string title, string message, string ok, DialogOptOutDecisionType dialogOptOutDecisionType, string dialogOptOutDecisionStorageKey);
public static bool DisplayDialog (string title, string message, string ok, string cancel= "", DialogOptOutDecisionType dialogOptOutDecisionType, string dialogOptOutDecisionStorageKey);

参数

title 消息框的名称。
message 消息的文本。
ok OK 对话框按钮上显示的标签。
cancel Cancel 对话框按钮上显示的标签。
dialogOptOutDecisionType 用户可以做出的选择退出决策的类型。
dialogOptOutDecisionStorageKey 用于存储决策的唯一键设置。

返回

bool 如果用户单击 ok 按钮,或以前选择不显示,则返回 /true/。如果用户取消或关闭对话框而不做出决策,则返回 /false/。

描述

此方法显示模态对话框,使用户可以选择不再次显示当前对话框。

Use this method to display dialog boxes in the Editor that might be shown repeatedly. Choose which EditorUtility.DialogOptOutDecisionType to use based on how often you think users encounter this message and how often you want to remind them of it.

如果用户选择不看到与提供的 dialogOptOutDecisionStorageKey 关联的对话框,则 Unity 不显示该对话框,并且此方法会立即返回 /true/。

okcancel 是对话框按钮上显示的标签。如果 cancel 为空,则按钮显示为“Cancel”。这是默认设置。如果用户按下 ok 按钮,则 DisplayDialog 返回 /true/。

If the user opts-out of the dialog box, Unity stores this decision. If dialogOptOutDecisionType is set to DialogOptOutDecisionType.ForThisMachine Unity stores the decision via EditorPrefs.SetBool. If dialogOptOutDecisionType is set to DialogOptOutDecisionType.ForThisSession Unity stores the decision via SessionState.SetBool. In both cases Unity stores the decision under the key provided as dialogOptOutDecisionStorageKey.

If you want to the let the user change the decision that is stored in EditorPrefs, you can add this to the Editor Preferences with a SettingsProvider.

Use DialogOptOutDecisionType.ForThisSession to show a dialog before a user performs a destructive action that might lose some of their work. If you think the user might see this dialog too often, you can add an option to the Editor Preferences with a SettingsProvider by using EditorPrefs and query that setting before showing the dialog.

See Also: EditorUtility.DisplayDialogComplex function.

// Places the selected Objects on the surface of a terrain.

using UnityEngine; using UnityEditor; using UnityEngine.UIElements;

public class PlaceSelectionOnSurface : ScriptableObject { const string placeOnSurfaceDialogDecisionKey = "Example.PlaceOnSurfaceDecision"; [MenuItem("Example/Place Selection On Surface")] static void CreateWizard() { Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep | SelectionMode.ExcludePrefab | SelectionMode.Editable);

if (transforms.Length > 0 && EditorUtility.DisplayDialog("Place Selection On Surface?", "Are you sure you want to place " + transforms.Length + " on the surface?", "Place", "Do Not Place", DialogOptOutDecisionType.ForThisMachine, placeOnSurfaceDialogDecisionKey)) { // Register and Undo event so that this action is not only not desctrutive but also easy to revert. // Without Undo, DialogOptOutDecisionType.ForThisSession would be a better fiting decision type. Undo.RecordObjects(transforms, "Place Selection On Surface"); foreach (Transform transform in transforms) { RaycastHit hit; if (Physics.Raycast(transform.position, -Vector3.up, out hit)) { transform.position = hit.point; Vector3 randomized = Random.onUnitSphere; randomized = new Vector3(randomized.x, 0F, randomized.z); transform.rotation = Quaternion.LookRotation(randomized, hit.normal); } } } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961