AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
DialogExampleLaunchButton.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
5 using HoloToolkit.UX.Dialog;
6 using System.Collections;
7 using UnityEngine;
8 
9 namespace HoloToolkit.Examples.UX
10 {
14  public class DialogExampleLaunchButton : MonoBehaviour
15  {
16  [SerializeField]
17  private Dialog dialogPrefab = null;
18 
19  [SerializeField]
20  private bool isDialogLaunched;
21 
22  [SerializeField]
23  private GameObject resultText;
28  public GameObject ResultText
29  {
30  get
31  {
32  return resultText;
33  }
34 
35  set
36  {
37  resultText = value;
38  }
39  }
40 
41  [SerializeField]
42  [Range(0,2)]
43  private int numButtons = 1;
44 
45  private TextMesh resultTextMesh;
46  private Button button;
47 
55  protected IEnumerator LaunchDialog(DialogButtonType buttons, string title, string message)
56  {
57  isDialogLaunched = true;
58 
59  //Open Dialog by sending in prefab
60  Dialog dialog = Dialog.Open(dialogPrefab.gameObject, buttons, title, message);
61 
62  if(dialog != null)
63  {
64  //listen for OnClosed Event
65  dialog.OnClosed += OnClosed;
66  }
67 
68  // Wait for dialog to close
69  while (dialog.State < DialogState.InputReceived)
70  {
71  yield return null;
72  }
73 
74  //only let one dialog be created at a time
75  isDialogLaunched = false;
76 
77  yield break;
78  }
79 
80  private void OnEnable()
81  {
82  resultTextMesh = ResultText.GetComponent<TextMesh>();
83  button = GetComponent<Button>();
84  if(button != null)
85  {
86  button.OnButtonClicked += OnButtonClicked;
87  }
88  }
89 
90  private void OnButtonClicked(GameObject obj)
91  {
92  if (isDialogLaunched == false)
93  {
94  if (numButtons == 1)
95  {
96  // Launch Dialog with single button
97  StartCoroutine(LaunchDialog(DialogButtonType.OK, "Single Button Dialog", "Dialogs and flyouts are transient UI elements that appear when something happens that requires notification, approval, or additional information from the user."));
98  }
99  else if (numButtons == 2)
100  {
101  // Launch Dialog with two buttons
102  StartCoroutine(LaunchDialog(DialogButtonType.Yes | DialogButtonType.No, "Two Buttons Dialog", "Dialogs and flyouts are transient UI elements that appear when something happens that requires notification, approval, or additional information from the user."));
103  }
104  }
105  }
106 
111  protected void OnClosed(DialogResult result)
112  {
113  // Get the result text from the Dialog
114  resultTextMesh.text = result.Result.ToString();
115  }
116  }
117 }
DialogButtonType
Enum describing the style (caption) of button on a Dialog.
DialogButtonType Result
Property reporting the Result of the Dialog: Which button was clicked to dismiss it.
Definition: DialogResult.cs:88
static Dialog Open(GameObject dialogPrefab, DialogResult result)
Instantiates a dialog and passes it a result
Definition: Dialog.cs:155
Action< DialogResult > OnClosed
Called after user has clicked a button and the dialog has finished closing
Definition: Dialog.cs:43
void OnClosed(DialogResult result)
Event Handler that fires when Dialog is closed- when a button on the Dialog is clicked.
DialogState
Enum that describes the current state of a Dialog.
Definition: DialogEnums.cs:9
IEnumerator LaunchDialog(DialogButtonType buttons, string title, string message)
This function is called to set the settings for the dialog and then open it.
Used to tell simple dialogs which buttons to create And to tell whatever launched the dialog which bu...
Definition: Dialog.cs:17
Demonstrates how to launch Dialog UI with different number of buttons
Action< GameObject > OnButtonClicked
Event fired when click interaction received.
Definition: Button.cs:76