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

参数

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

描述

显示模态对话框。

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

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

另请参阅:DisplayDialogComplex 函数。

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

// 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")) { 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); } } } } }