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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ There is also async overload:
await Notifications.SendAsync("Warning!", NotificationType.Warning);
```

You can also hook Translation / any fuction to handle messages before sending like so:
```c#
private void Start()
{
Notifications.TranslationFunction = Translate;
}

private string Translate(string key)
{
// Do something.
return key;
}
```

## Install

### via npm
Expand Down
15 changes: 14 additions & 1 deletion Runtime/Notifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public class Notifications : MonoBehaviour
[SerializeField] private GameObject notificationPrefab;
#pragma warning restore CS0649

public static Func<string, string> TranslationFunction
{
set => instance.translationFunction = value;
}

private Func<string, string> translationFunction;

// Singleton design, assigned in Awake().
private static Notifications instance;

Expand Down Expand Up @@ -229,7 +236,13 @@ private void SendNotification(Notification notification)
? CreateNotificationDynamically(transform)
: Instantiate(notificationPrefab, transform);
var rect = notificationGameObject.GetComponent<RectTransform>();
notificationGameObject.GetComponent<NotificationUI>().SetUp(notification.Message, GetColor(notification.Type), notification.OnClickEvent);

var message = notification.Message;
if (translationFunction != null)
{
message = translationFunction(message);
}
notificationGameObject.GetComponent<NotificationUI>().SetUp(message, GetColor(notification.Type), notification.OnClickEvent);

var slotIndex = GetIndexOfFreeSlot();

Expand Down