| | 1 | | using System; |
| | 2 | | using DCL.NotificationModel; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | public class NotificationHUDView : MonoBehaviour |
| | 6 | | { |
| | 7 | | public NotificationFactory notificationFactory; |
| | 8 | |
|
| | 9 | | [SerializeField] |
| | 10 | | private RectTransform notificationPanel; |
| | 11 | |
|
| | 12 | | public event Action<INotification> OnNotificationDismissedEvent; |
| | 13 | |
|
| | 14 | | private const string VIEW_PATH = "NotificationHUD"; |
| | 15 | | private const string VIEW_OBJECT_NAME = "_NotificationHUD"; |
| | 16 | |
|
| | 17 | | internal static NotificationHUDView Create() |
| | 18 | | { |
| 16 | 19 | | NotificationHUDView view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<NotificationHUDView>( |
| 16 | 20 | | view.Initialize(); |
| 16 | 21 | | return view; |
| | 22 | | } |
| | 23 | |
|
| 32 | 24 | | private void Initialize() { gameObject.name = VIEW_OBJECT_NAME; } |
| | 25 | |
|
| | 26 | | public void ShowNotification(INotification notification, Model model = null) |
| | 27 | | { |
| 6 | 28 | | if (notification == null) |
| 0 | 29 | | return; |
| | 30 | |
|
| 6 | 31 | | notification.OnNotificationDismissed += OnNotificationDismissed; |
| | 32 | |
|
| 6 | 33 | | if (model != null) |
| 6 | 34 | | notification.Show(model); |
| 6 | 35 | | } |
| | 36 | |
|
| | 37 | | public Notification ShowNotification(Model notificationModel) |
| | 38 | | { |
| 4 | 39 | | if (notificationModel == null) |
| 0 | 40 | | return null; |
| | 41 | |
|
| 4 | 42 | | Notification notification = notificationFactory.CreateNotificationFromType(notificationModel.type, notificationP |
| 4 | 43 | | notificationModel.destroyOnFinish = true; |
| 4 | 44 | | ShowNotification(notification, notificationModel); |
| 4 | 45 | | return notification; |
| | 46 | | } |
| | 47 | |
|
| 2 | 48 | | private void OnNotificationDismissed(INotification notification) { OnNotificationDismissedEvent?.Invoke(notification |
| | 49 | |
|
| 2 | 50 | | public void SetActive(bool active) { gameObject.SetActive(active); } |
| | 51 | | } |