Skip to content

Commit 90d4b5b

Browse files
committed
Add comments in C# scripts
1 parent 6ac33f4 commit 90d4b5b

7 files changed

Lines changed: 107 additions & 4 deletions

File tree

Assets/NativeDialogSample.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,41 @@
22
using System.Collections;
33
using NativeDialog;
44

5+
/// <summary>
6+
/// Sample component demonstrating the usage of native dialog functionality.
7+
/// Provides various examples of showing select and submit dialogs with different configurations.
8+
/// </summary>
59
public class NativeDialogSample : MonoBehaviour
610
{
11+
/// <summary>
12+
/// Label text for the positive/confirm button in dialogs.
13+
/// </summary>
714
[SerializeField] private string decideLabel = "Decide";
15+
16+
/// <summary>
17+
/// Label text for the negative/reject button in dialogs.
18+
/// </summary>
819
[SerializeField] private string cancelLabel = "Cancel";
20+
21+
/// <summary>
22+
/// Label text for the close button in submit-only dialogs.
23+
/// </summary>
924
[SerializeField] private string closeLabel = "Close";
1025

26+
/// <summary>
27+
/// Initializes the dialog labels when the component starts.
28+
/// </summary>
1129
private void Start()
1230
{
1331
DialogManager.SetLabel(decideLabel, cancelLabel, closeLabel);
1432
}
1533

1634
#region Invoked from Unity GUI
1735

36+
/// <summary>
37+
/// Shows a simple selection dialog with OK/Cancel buttons.
38+
/// Logs the user's choice to the console.
39+
/// </summary>
1840
public void ShowSelectDialog()
1941
{
2042
const string message = "A simple select dialog";
@@ -24,6 +46,10 @@ public void ShowSelectDialog()
2446
});
2547
}
2648

49+
/// <summary>
50+
/// Shows a selection dialog with both title and message.
51+
/// Useful for providing more context to the user.
52+
/// </summary>
2753
public void ShowSelectDialogWithTitle()
2854
{
2955
const string title = "A title";
@@ -34,6 +60,10 @@ public void ShowSelectDialogWithTitle()
3460
});
3561
}
3662

63+
/// <summary>
64+
/// Shows a submit-only dialog with a single OK button.
65+
/// Used for notifications or acknowledgments.
66+
/// </summary>
3767
public void ShowSubmitDialog()
3868
{
3969
const string message = "A simple submit dialog";
@@ -43,6 +73,10 @@ public void ShowSubmitDialog()
4373
});
4474
}
4575

76+
/// <summary>
77+
/// Shows a submit dialog with both title and message.
78+
/// Provides a more detailed notification to the user.
79+
/// </summary>
4680
public void ShowSubmitDialogWithTitle()
4781
{
4882
const string title = "A title";
@@ -53,6 +87,10 @@ public void ShowSubmitDialogWithTitle()
5387
});
5488
}
5589

90+
/// <summary>
91+
/// Shows a dialog that automatically dismisses after 3 seconds.
92+
/// Demonstrates how to programmatically close dialogs.
93+
/// </summary>
5694
public void ShowDialogWithAutoDismiss()
5795
{
5896
const string message = "A dialog with auto dismiss";

Packages/com.github.asus4.nativedialog/Runtime/DialogManager.cs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
namespace NativeDialog
66
{
77
/// <summary>
8-
/// Popup Native Dialog
8+
/// Manages Native Dialog popups across different platforms.
9+
/// Provides a unified interface for showing native select and submit dialogs on iOS, Android, and Unity Editor.
910
/// </summary>
1011
public sealed class DialogManager : MonoBehaviour, IDialogReceiver
1112
{
1213

1314
#region Singleton
1415
private static DialogManager instance;
16+
17+
/// <summary>
18+
/// Gets the singleton instance of DialogManager.
19+
/// Creates a new instance if one doesn't exist.
20+
/// </summary>
1521
public static DialogManager Instance
1622
{
1723
get
@@ -33,10 +39,11 @@ public static DialogManager Instance
3339

3440
#region Members
3541
private Dictionary<int, Action<bool>> callbacks;
42+
3643
private IDialog dialog;
3744
#endregion
3845

39-
#region Lyfecycles
46+
#region Lifecycles
4047
private void Awake()
4148
{
4249
if (instance == null)
@@ -92,39 +99,78 @@ private void OnDestroy()
9299
}
93100
#endregion
94101

102+
#region Public Methods
103+
104+
/// <summary>
105+
/// Sets the button labels for all future dialogs.
106+
/// </summary>
107+
/// <param name="decide">Label for the positive/confirm button</param>
108+
/// <param name="cancel">Label for the negative/cancel button</param>
109+
/// <param name="close">Label for the close button in submit dialogs</param>
95110
public static void SetLabel(string decide, string cancel, string close)
96111
{
97112
Instance.dialog.SetLabel(decide, cancel, close);
98113
}
99114

115+
/// <summary>
116+
/// Shows a selection dialog with OK/Cancel buttons.
117+
/// </summary>
118+
/// <param name="message">The message to display</param>
119+
/// <param name="callback">Callback invoked with true for OK, false for Cancel</param>
120+
/// <returns>Dialog ID that can be used to dismiss the dialog</returns>
100121
public static int ShowSelect(string message, Action<bool> callback)
101122
{
102123
int id = Instance.dialog.ShowSelect(message);
103124
Instance.callbacks.Add(id, callback);
104125
return id;
105126
}
106127

128+
/// <summary>
129+
/// Shows a selection dialog with title and OK/Cancel buttons.
130+
/// </summary>
131+
/// <param name="title">The dialog title</param>
132+
/// <param name="message">The message to display</param>
133+
/// <param name="callback">Callback invoked with true for OK, false for Cancel</param>
134+
/// <returns>Dialog ID that can be used to dismiss the dialog</returns>
107135
public static int ShowSelect(string title, string message, Action<bool> callback)
108136
{
109137
int id = Instance.dialog.ShowSelect(title, message);
110138
Instance.callbacks.Add(id, callback);
111139
return id;
112140
}
113141

142+
/// <summary>
143+
/// Shows a submit dialog with only an OK button.
144+
/// </summary>
145+
/// <param name="message">The message to display</param>
146+
/// <param name="callback">Callback invoked when the dialog is closed</param>
147+
/// <returns>Dialog ID that can be used to dismiss the dialog</returns>
114148
public static int ShowSubmit(string message, Action<bool> callback)
115149
{
116150
int id = Instance.dialog.ShowSubmit(message);
117151
Instance.callbacks.Add(id, callback);
118152
return id;
119153
}
120154

121-
public static int ShowSubmit(string title, string message, Action<bool> del)
155+
/// <summary>
156+
/// Shows a submit dialog with title and only an OK button.
157+
/// </summary>
158+
/// <param name="title">The dialog title</param>
159+
/// <param name="message">The message to display</param>
160+
/// <param name="callback">Callback invoked when the dialog is closed</param>
161+
/// <returns>Dialog ID that can be used to dismiss the dialog</returns>
162+
public static int ShowSubmit(string title, string message, Action<bool> callback)
122163
{
123164
int id = Instance.dialog.ShowSubmit(title, message);
124-
Instance.callbacks.Add(id, del);
165+
Instance.callbacks.Add(id, callback);
125166
return id;
126167
}
127168

169+
/// <summary>
170+
/// Programmatically dismisses a dialog.
171+
/// Invokes the callback with false (cancelled).
172+
/// </summary>
173+
/// <param name="id">The ID of the dialog to dismiss</param>
128174
public static void Dismiss(int id)
129175
{
130176
Instance.dialog.Dismiss(id);
@@ -141,6 +187,7 @@ public static void Dismiss(int id)
141187
}
142188
}
143189

190+
#endregion // Public Methods
144191

145192
#region Invoked from Native Plugin
146193
public void OnSubmit(string idStr)

Packages/com.github.asus4.nativedialog/Runtime/Internal/DialogAndroid.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace NativeDialog
66
{
7+
/// <summary>
8+
/// Android-specific implementation of native dialogs using AndroidJavaClass.
9+
/// </summary>
710
internal sealed class DialogAndroid : IDialog
811
{
912
private readonly AndroidJavaClass cls;

Packages/com.github.asus4.nativedialog/Runtime/Internal/DialogIOS.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace NativeDialog
66
{
7+
/// <summary>
8+
/// iOS-specific implementation of native dialogs using DllImport to call native methods.
9+
/// </summary>
710
internal sealed class DialogIOS : IDialog
811
{
912
public void Dispose()

Packages/com.github.asus4.nativedialog/Runtime/Internal/DialogMock.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
namespace NativeDialog
55
{
6+
/// <summary>
7+
/// Mock implementation of dialogs for Unity Editor testing.
8+
/// Simulates dialog behavior with configurable delays and results.
9+
/// </summary>
610
internal sealed class DialogMock : MonoBehaviour, IDialog
711
{
812
[SerializeField]

Packages/com.github.asus4.nativedialog/Runtime/Internal/IDialog.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
namespace NativeDialog
22
{
3+
/// <summary>
4+
/// Interface for platform-specific dialog implementations.
5+
/// Defines methods for showing native dialogs across different platforms.
6+
/// </summary>
37
internal interface IDialog : System.IDisposable
48
{
59
void SetLabel(string decide, string cancel, string close);

Packages/com.github.asus4.nativedialog/Runtime/Internal/IDialogReceiver.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
namespace NativeDialog
22
{
3+
/// <summary>
4+
/// Interface for receiving callbacks from native dialog implementations.
5+
/// Handles user interactions with dialog buttons.
6+
/// </summary>
37
internal interface IDialogReceiver
48
{
59
void OnSubmit(string idStr);

0 commit comments

Comments
 (0)