如何使用Unity 的 MRTK(混合现实工具包)中的对话框

对话框控件是 UI 覆盖层,提供上下文应用信息(通常是请求用户执行操作)。 使用对话框可以向用户提供重要信息,并在完成某项操作之前请求确认或附加信息。

Unity 的 MRTK(混合现实工具包)中的对话框

MRTK 提供三种大小的对话框控件,其中包含一个或两个按钮选项。 你还可以指定近距或远距交互范围的定位距离。

  • DialogSmall_192x96.prefab: 192x96mm
  • DialogMedium_192x128.prefab:192×128 毫米
  • DialogLarge_192x192.prefab: 192x192mm
Screenshot of different size dialog overlays running on HoloLens

使用 Dialog.Open () 打开新对话框。 指定对话框预制、按钮数、标题文本、消息文本、放置距离 (或) 位置、其他) 。 对话框提供”确认 (按钮) “和”选择 (按钮) “对话框选项。

public static Dialog Open(GameObject dialogPrefab, DialogButtonType buttons, string title, string message, bool placeForNearInteraction, System.Object variable = null)

使用单个”确定”按钮打开大型对话的示例,该按钮放置在远交互范围内 (凝视、手部射线、运动控制器)

Dialog.Open(DialogPrefabLarge, DialogButtonType.OK, “Confirmation Dialog, Large, Far”, “This is an example of a large dialog with only one button, placed at far interaction range”, false);

打开包含用户选择消息的”小”对话框的示例,该对话框放置在近交互范围内 (直接手动交互)

Dialog.Open(DialogPrefabSmall, DialogButtonType.Yes | DialogButtonType.No, “Confirmation Dialog, Small, Near”, “This is an example of a small dialog with a choice message, placed at near interaction range”, true);