77 lines
1.4 KiB
C#
77 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UIWidgets
|
|
{
|
|
public class NotifySequenceManager : MonoBehaviour
|
|
{
|
|
private static Notify currentNotify;
|
|
|
|
private static List<Notify> notifySequence = new List<Notify>();
|
|
|
|
private IEnumerator nextDelay;
|
|
|
|
public void Clear()
|
|
{
|
|
if (currentNotify != null)
|
|
{
|
|
currentNotify.Return();
|
|
currentNotify = null;
|
|
}
|
|
notifySequence.ForEach(ReturnNotify);
|
|
notifySequence.Clear();
|
|
}
|
|
|
|
private void ReturnNotify(Notify notify)
|
|
{
|
|
notify.Return();
|
|
}
|
|
|
|
public void Add(Notify notification, NotifySequence type)
|
|
{
|
|
if (type == NotifySequence.Last)
|
|
{
|
|
notifySequence.Add(notification);
|
|
}
|
|
else
|
|
{
|
|
notifySequence.Insert(0, notification);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!(currentNotify != null) && notifySequence.Count != 0)
|
|
{
|
|
currentNotify = notifySequence[0];
|
|
notifySequence.RemoveAt(0);
|
|
currentNotify.Display(NotifyDelay);
|
|
}
|
|
}
|
|
|
|
private void NotifyDelay()
|
|
{
|
|
if (nextDelay != null)
|
|
{
|
|
StopCoroutine(nextDelay);
|
|
}
|
|
if (notifySequence.Count > 0 && notifySequence[0].SequenceDelay > 0f)
|
|
{
|
|
nextDelay = NextDelay();
|
|
StartCoroutine(nextDelay);
|
|
}
|
|
else
|
|
{
|
|
currentNotify = null;
|
|
}
|
|
}
|
|
|
|
private IEnumerator NextDelay()
|
|
{
|
|
yield return new WaitForSeconds(notifySequence[0].SequenceDelay);
|
|
currentNotify = null;
|
|
}
|
|
}
|
|
}
|