using System; using Convai.Scripts.Runtime.LoggerSystem; using UnityEngine; namespace Convai.Scripts.Runtime.Addons { /// /// 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; /// /// Flag indicating whether the notification system is currently active. /// private bool _isNotificationSystemActive = true; /// /// Event triggered when a notification is requested. /// public Action OnNotificationRequested; /// /// 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) { ConvaiLogger.DebugLog(" There's More Than One NotificationSystemHandler " + transform + " - " + Instance, ConvaiLogger.LogCategory.UI); 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) { ConvaiLogger.Error("There is no Notification defined for the selected Notification Type!", ConvaiLogger.LogCategory.UI); 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; } } }