Skip to content

Commit ea8b35e

Browse files
committed
Update Unity package doc file
1 parent 000407d commit ea8b35e

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
1-
# Index
1+
# Unity simple notifications
22

3-
- table of contents goes here
3+
Simple but powerful UI notifications package for Unity game engine.
4+
5+
- [How to use](#how-to-use)
6+
- [Performance and thread safety](#performance-and-thread-safety)
7+
- [Configuration](#configuration)
8+
9+
<!-- toc -->
10+
11+
## How to use
12+
13+
1. Right click scene hierarchy
14+
2. Click UI/Notifications
15+
16+
![HowTo](images/HowTo.png)
17+
18+
Now you can send Notifications from your script like this:
19+
```c#
20+
Notifications.Send("Hello world");
21+
```
22+
23+
![Notification](images/SimpleShowCase.gif)
24+
25+
Specify type (changes notification color) and click events with optional parameters:
26+
```c#
27+
private void Error()
28+
{
29+
Notifications.Send("Spooky error!", NotificationType.Error, OnClick);
30+
}
31+
32+
public void OnClick()
33+
{
34+
// Do something.
35+
}
36+
```
37+
There is also async overload:
38+
```c#
39+
await Notifications.SendAsync("Warning!", NotificationType.Warning);
40+
```
41+
42+
## Performance and thread safety
43+
44+
- Notifications are rate limited based on duplicates sent recently and max notifications queue length
45+
- Notifications can be send from another thread. Creating GameObjects still always happens on main thread
46+
47+
Here is how it looks when billion notifications are sent simultaneously from another thread:
48+
49+
![Notification](images/PerformanceShowCase.gif)
50+
51+
Try it yourself! Code:
52+
```c#
53+
using UnityEngine;
54+
using System.Threading;
55+
using Group3d.Notifications;
56+
57+
public class TEST : MonoBehaviour
58+
{
59+
private void Start()
60+
{
61+
new Thread(() =>
62+
{
63+
Thread.CurrentThread.IsBackground = true;
64+
var r = new System.Random();
65+
int counter = 0;
66+
while (counter < 1000000000)
67+
{
68+
Notifications.Send($"Test {r.Next(0, 10000)}");
69+
counter++;
70+
}
71+
}).Start();
72+
}
73+
}
74+
75+
```
76+
77+
## Configuration
78+
79+
Confurable from the inspector:
80+
81+
![Inspector](images/Inspector.png)
82+
83+
Custom notification prefab can be created and assigned in the inspector. If doing so, consider these things:
84+
- Prefab must have NotificationUI component (included in the package)
85+
- Prefab must have RectTransform component with anchors set to top-stretch
86+
87+
If prefab is null, notification will be created dynamically.
88+
89+
Optional Font parameter is only used when notification is created dynamically - if that is the only thing you want to change.

0 commit comments

Comments
 (0)