Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 13 additions & 27 deletions Runtime/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class Notifications : MonoBehaviour

private Timer cleanUpTimer;
private float sendNotificationTimer = -1;
private bool sendingNotifications;

private void Awake()
{
Expand All @@ -68,38 +67,27 @@ private void Awake()

private void Update()
{
if (sendingNotifications)
if (notificationsToSend.Count > 0 && sendNotificationTimer <= 0)
{
if (sendNotificationTimer <= 0)
if (notificationsToSend.TryDequeue(out var notification))
{
SendNotifications();
sendNotificationTimer = sendNotificationIntervalInMs / 1000f;
SendNotification(notification);
}
else

if (notificationsRateLimitedCount > 0)
{
sendNotificationTimer -= Time.deltaTime;
#if DEBUG || UNITY_EDITOR
Debug.LogWarning($"Duplicate notifications rate limited: {notificationsRateLimitedCount}");
#endif
notificationsRateLimitedCount = 0;
}
}
}

private void SendNotifications()
{
if (notificationsToSend.Count > 0 && notificationsToSend.TryDequeue(out var notification))
{
SendNotification(notification);
sendNotificationTimer = sendNotificationIntervalInMs / 1000f;
}
else

if (sendNotificationTimer > 0)
{
sendingNotifications = false;
sendNotificationTimer = -1f;
}

if (notificationsRateLimitedCount > 0)
{
#if DEBUG || UNITY_EDITOR
Debug.LogWarning($"Duplicate notifications rate limited: {notificationsRateLimitedCount}");
#endif
notificationsRateLimitedCount = 0;
sendNotificationTimer -= Time.deltaTime;
}
}

Expand Down Expand Up @@ -188,8 +176,6 @@ private async Task HandleNotificationAsync(Notification notification)

await Task.Run(() =>
{
sendingNotifications = true;

var hash = notification.Message.GetHashCode();
var timestamp = DateTime.Now.Ticks;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.3d-group.unity-simple-notifications",
"displayName": "3D Group - Notifications",
"version": "1.1.1",
"version": "1.2.0",
"unity": "2019.4",
"description": "Simple UI notifications for Unity game engine.",
"keywords": [
Expand Down