jimmy tremblay-Bernier c1bf5a4ca1 initial commit
2022-03-12 22:04:30 -04:00

58 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PopupUI : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI TextMessage;
[SerializeField] private TextMeshProUGUI TextHighlight;
[SerializeField] private string TextValue;
[SerializeField] private int PopupsQueueDelay = 4;
private List<Popup> popups;
private Animator animator;
private AudioSource audioSource;
private void Awake()
{
animator = GetComponent<Animator>();
audioSource = GetComponent<AudioSource>();
popups = new List<Popup>();
}
public void SetPopup(string text, bool setAsAlert = false)
{
popups.Add(new Popup { message = text, isAlert = setAsAlert });
if (popups.Count == 1)
StartCoroutine(NextPopup());
}
public IEnumerator NextPopup()
{
TextValue = popups[0].message;
Debug.Log(TextValue);
TextMessage.text = $"<mark=#00000000 padding=\"10, 10, 0, 0\">{TextValue}</mark>";
TextHighlight.text = $"<mark=#000000AA padding=\"10, 10, 0, 0\">{TextValue}</mark>";
animator.SetTrigger("PopupActivated");
if (popups[0].isAlert)
{
audioSource.enabled = true;
}
yield return new WaitForSeconds(PopupsQueueDelay);
audioSource.enabled = false;
popups.RemoveAt(0);
if (popups.Count != 0) StartCoroutine(NextPopup());
}
}
struct Popup
{
public string message;
public bool isAlert;
}