settings
This commit is contained in:
82
Assets/Scripts/UI/Common/Panel/Information/NoticesPanel.cs
Normal file
82
Assets/Scripts/UI/Common/Panel/Information/NoticesPanel.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user