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