AlicizaX/Client/Packages/com.alicizax.unity.ui/Runtime/UI/Base/Manager/UIManager.Cache.cs
2025-01-24 16:21:00 +08:00

72 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using AlicizaX.Runtime;
namespace AlicizaX.UI.Runtime
{
internal sealed partial class UIManager
{
private readonly Dictionary<Type, int> mWindowDisposeTimerIds = new Dictionary<Type, int>();
private readonly Dictionary<Type, PanelInfo> m_CacheWindow = new Dictionary<Type, PanelInfo>();
private bool InCache(Type type)
{
return m_CacheWindow.ContainsKey(type);
}
private void CacheWindow(PanelInfo info)
{
if (info == null)
{
Log.Error("{0} panelinfo not exist!", info.UIClsType.FullName);
return;
}
if (info.UIBasePanel == null)
{
Log.Error("{0} PanelObject not exist!", info.UIClsType.FullName);
return;
}
info.SetPanelState(EPanelState.Cache);
m_CacheWindow.Add(info.UIClsType, info);
SetPanelLayer(info, UILayer.Cache);
if (info.DelayedClose > 0)
{
RemoveTimerDispose(info.UIClsType);
int hideTimerId =_timerManager.AddTimer(OnTimerDiposeWindow, info.DelayedClose, false, true, info);
mWindowDisposeTimerIds.Add(info.UIClsType, hideTimerId);
}
}
private void OnTimerDiposeWindow(object[] args)
{
PanelInfo info = args[0] as PanelInfo;
info.UIBasePanel.InternalDestroy();
m_CacheWindow.Remove(info.UIClsType);
info.Reset(null);
info.SetPanelState(EPanelState.None);
}
private void RemoveTimerDispose(Type type)
{
if (mWindowDisposeTimerIds.TryGetValue(type, out int tiemrId))
{
_timerManager.RemoveTimer(tiemrId);
mWindowDisposeTimerIds.Remove(type);
}
}
private void RemoveFromCache(PanelInfo info)
{
m_CacheWindow.Remove(info.UIClsType);
if (mWindowDisposeTimerIds.TryGetValue(info.UIClsType, out int tiemrId))
{
_timerManager.RemoveTimer(tiemrId);
mWindowDisposeTimerIds.Remove(info.UIClsType);
}
}
}
}