123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class InGameNotificationManager : MonoBehaviour {
- public static InGameNotificationManager Instance;
- public UIElementsGroup NotificationUI;
- public Text Title;
- public Text Body;
- private bool activeNotification;
- private List<NotificationData> queuedNotifications = new List<NotificationData>();
- public struct NotificationData
- {
- public string Title;
- public string Body;
- public NotificationData(string title, string body)
- {
- Title = title;
- Body = body;
- }
- }
- void Awake()
- {
- Instance = this;
- }
- void Update()
- {
- if (Input.GetKeyDown("n"))
- PopNotification("Quest Completed!", "Your First Gig");
- }
-
- public void PopNotification(string title, string body)
- {
- if (activeNotification)
- {
- queuedNotifications.Add(new NotificationData(title, body));
- return;
- }
- NotificationUI.ChangeVisibility(true);
- Title.text = title;
- Body.text = body;
- StartCoroutine(ExtraLetter());
- Invoke("CloseNotification", 3);
- activeNotification = true;
- }
- IEnumerator ExtraLetter()
- {
- yield return null;
- Body.text += " ";
- yield return null;
- Body.text = Body.text.Substring(0, Body.text.Length -1);
- }
- public void CloseNotification()
- {
- activeNotification = false;
- NotificationUI.ChangeVisibility(false);
- CancelInvoke("CloseNotification");
- if (queuedNotifications.Count > 0)
- {
- NotificationUI.ChangeVisibilityImmediate(false);
- NotificationData qData = queuedNotifications[0];
- PopNotification(qData.Title, qData.Body);
- queuedNotifications.RemoveAt(0);
- }
- }
- }
|