using System;
using UnityEngine;
///
/// Handles the notification system's behavior and interactions.
///
[DefaultExecutionOrder(-100)]
public class NotificationSystemHandler : MonoBehaviour
{
///
/// Array containing predefined notification configurations.
/// This array can be modified in the Unity Editor to define different types of notifications.
///
[SerializeField] private SONotificationGroup _notificationGroup;
///
/// Event triggered when a notification is requested.
///
public Action OnNotificationRequested;
///
/// Flag indicating whether the notification system is currently active.
///
private bool _isNotificationSystemActive = true;
///
/// Singleton instance of the NotificationSystemHandler.
///
public static NotificationSystemHandler Instance { get; private set; }
///
/// Ensure there is only one instance of NotificationSystemHandler.
///
private void Awake()
{
if (Instance != null)
{
Debug.Log(" There's More Than One NotificationSystemHandler " + transform + " - " +
Instance);
Destroy(gameObject);
return;
}
Instance = this;
}
///
/// Requests a notification of the specified type.
///
/// The type of notification to request.
public void NotificationRequest(NotificationType notificationType)
{
// Check if the notification system is currently active.
if (!_isNotificationSystemActive) return;
// Search for the requested notification type in the predefined array.
SONotification requestedSONotification = null;
foreach (SONotification notification in _notificationGroup.SONotifications)
if (notification.NotificationType == notificationType)
{
requestedSONotification = notification;
break;
}
// If the requested notification is not found, log an error.
if (requestedSONotification == null)
{
Debug.LogError("There is no Notification defined for the selected Notification Type!");
return;
}
// Invoke the OnNotificationRequested event with the requested notification.
OnNotificationRequested?.Invoke(requestedSONotification);
}
///
/// Sets the activation status of the notification system.
///
/// The new activation status.
public void SetNotificationSystemActiveStatus(bool value)
{
_isNotificationSystemActive = value;
}
}