NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/SubSystems/ScrollNoticeManager.cs

81 lines
1.8 KiB
C#

using Cysharp.Threading.Tasks;
using Framework;
using PhxhSDK;
using System.Collections.Generic;
public class ScrollNoticeManager : Singlenton<ScrollNoticeManager>
{
private bool allowNotice = true;
private bool isShow = false;
private Queue<string> receives = new Queue<string>();
void ShowNotice()
{
if (receives.Count > 0 && allowNotice && !isShow)
{
string notice = receives.Dequeue();
isShow = true;
DebugUtil.Log("展示滚动公告:" + notice);
UIManager.Instance.CreateAndOpenWindow(UINameConst.UIScrollNotice, notice).Forget();
}
}
/// <summary>
/// 一条通告显示完毕后的冷却时间
/// </summary>
async void Cooldown()
{
await UniTask.Delay(1000);
ShowNotice();
}
#region public
/// <summary>
/// 设置当前是否允许显示滚动公告
/// </summary>
/// <param name="allow"></param>
public void SetAllowNotice(bool allow)
{
allowNotice = allow;
if (allowNotice)
{
ShowNotice();
}
}
/// <summary>
/// 添加滚动公告
/// </summary>
/// <param name="notice"></param>
public void AddNotice(string notice)
{
for (int i = 0; i < TableManager.Instance.Tables.GlobalConfig.NotificationLoopCount; i++)
receives.Enqueue(notice);
DebugUtil.Log("添加滚动公告:" + notice);
if(!isShow && allowNotice)
{
ShowNotice();
}
}
/// <summary>
/// 当前滚动公告显示完成
/// </summary>
public void ShowFinished()
{
isShow = false;
Cooldown();
}
/// <summary>
/// 清空滚动公告
/// </summary>
public void ClearNotice()
{
receives.Clear();
}
#endregion
}