Files
Fishing2/Assets/Scripts/UI/Common/Panel/Information/NoticesPanel.cs
Bob.Song 830cf3c354 settings
2026-03-25 17:07:05 +08:00

82 lines
2.2 KiB
C#

// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using System.Collections.Generic;
using System.Linq;
using FairyGUI;
using UnityEngine;
using NBC;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public partial class NoticesPanel : UIPanel
{
private static HashSet<INoticeComponent> _noticeComponents = new();
private static Queue<INoticeComponent> _waitAddComponents = new();
private static bool _isOpen;
public static void TryAddNoticeComponent(INoticeComponent noticeComponent)
{
if (!_isOpen)
{
Show();
}
if (_noticeComponents.Any(iNoticeComponent => iNoticeComponent.GetType() == noticeComponent.GetType()))
{
return;
}
if (_waitAddComponents.Any(waitAddComponent => waitAddComponent.GetType() == noticeComponent.GetType()))
{
return;
}
_waitAddComponents.Enqueue(noticeComponent);
}
protected override void OnInit()
{
ContentPane.sortingOrder = UIDef.UIOrder.Notices;
}
protected override void OnShow()
{
_isOpen = true;
}
protected override void OnUpdate()
{
foreach (var noticeComponent in _noticeComponents)
{
noticeComponent?.OnUpdate();
}
if (_waitAddComponents.Count > 0)
{
var com = _waitAddComponents.Dequeue();
var noticeComponent = UIPackage.CreateObject(UIDef.Pack.Common, "CommonContainer") as GComponent;
noticeComponent.width = ContentPane.width;
noticeComponent.height = ContentPane.height;
ContentPane.AddChild(noticeComponent);
com.OnInit(noticeComponent);
_noticeComponents.Add(com);
}
}
protected override void OnHide()
{
_isOpen = false;
}
protected override void OnDestroy()
{
foreach (var noticeComponent in _noticeComponents)
{
noticeComponent?.OnDestroy();
}
}
}
}