-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathNativeDialogSample.cs
More file actions
111 lines (99 loc) · 3.31 KB
/
NativeDialogSample.cs
File metadata and controls
111 lines (99 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using UnityEngine;
using System.Collections;
using NativeDialog;
/// <summary>
/// Sample component demonstrating the usage of native dialog functionality.
/// Provides various examples of showing select and submit dialogs with different configurations.
/// </summary>
public class NativeDialogSample : MonoBehaviour
{
/// <summary>
/// Label text for the positive/confirm button in dialogs.
/// </summary>
[SerializeField] private string decideLabel = "Decide";
/// <summary>
/// Label text for the negative/reject button in dialogs.
/// </summary>
[SerializeField] private string cancelLabel = "Cancel";
/// <summary>
/// Label text for the close button in submit-only dialogs.
/// </summary>
[SerializeField] private string closeLabel = "Close";
/// <summary>
/// Initializes the dialog labels when the component starts.
/// </summary>
private void Start()
{
DialogManager.SetLabel(decideLabel, cancelLabel, closeLabel);
}
#region Invoked from Unity GUI
/// <summary>
/// Shows a simple selection dialog with OK/Cancel buttons.
/// Logs the user's choice to the console.
/// </summary>
public void ShowSelectDialog()
{
const string message = "A simple select dialog";
DialogManager.ShowSelect(message, (bool result) =>
{
Debug.Log($"{result}: {message}");
});
}
/// <summary>
/// Shows a selection dialog with both title and message.
/// Useful for providing more context to the user.
/// </summary>
public void ShowSelectDialogWithTitle()
{
const string title = "A title";
const string message = "A message for select dialog";
DialogManager.ShowSelect(title, message, (bool result) =>
{
Debug.Log($"{result}: {title} / {message}");
});
}
/// <summary>
/// Shows a submit-only dialog with a single OK button.
/// Used for notifications or acknowledgments.
/// </summary>
public void ShowSubmitDialog()
{
const string message = "A simple submit dialog";
DialogManager.ShowSubmit(message, (bool result) =>
{
Debug.Log($"{result}: {message}");
});
}
/// <summary>
/// Shows a submit dialog with both title and message.
/// Provides a more detailed notification to the user.
/// </summary>
public void ShowSubmitDialogWithTitle()
{
const string title = "A title";
const string message = "A message for submit dialog";
DialogManager.ShowSubmit(title, message, (bool result) =>
{
Debug.Log($"{result}: {title} / {message}");
});
}
/// <summary>
/// Shows a dialog that automatically dismisses after 3 seconds.
/// Demonstrates how to programmatically close dialogs.
/// </summary>
public void ShowDialogWithAutoDismiss()
{
const string message = "A dialog with auto dismiss";
int id = DialogManager.ShowSelect(message, (bool result) =>
{
Debug.Log($"{result}: {message}");
});
StartCoroutine(Dismiss(id, 3f));
}
#endregion // Invoked from Unity GUI
private IEnumerator Dismiss(int id, float time)
{
yield return new WaitForSeconds(time);
DialogManager.Dismiss(id);
}
}