using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Convai.Scripts.Runtime.Addons
{
///
/// Represents a UI notification element that can be activated or deactivated.
///
public class UINotification : MonoBehaviour
{
///
/// The RectTransform of the notification UI element.
///
public RectTransform NotificationRectTransform;
///
/// The image component for displaying the notification icon.
///
[SerializeField] private Image _notificationIcon;
///
/// The TextMeshProUGUI component for displaying the notification title.
///
[SerializeField] private TextMeshProUGUI _notificationTitleText;
///
/// The TextMeshProUGUI component for displaying the notification text.
///
[SerializeField] private TextMeshProUGUI _notificationMessageText;
///
/// Deactivates the notification UI element on awake.
///
private void Awake()
{
SetActive(false);
}
///
/// Initializes the UI notification with the provided Notification data.
///
/// The notification data to initialize the UI notification with.
public void Initialize(SONotification soNotification)
{
if (soNotification == null) throw new ArgumentNullException(nameof(soNotification), "SONotification is null.");
// Set the notification icon and text based on the provided Notification.
_notificationIcon.sprite = soNotification.Icon;
_notificationTitleText.text = soNotification.NotificationTitle;
_notificationMessageText.text = soNotification.NotificationMessage;
// Activate the notification UI element.
SetActive(true);
}
///
/// Sets the active state of the notification UI element.
///
/// The new active state.
public void SetActive(bool value)
{
gameObject.SetActive(value);
}
}
}