using System; using System.Collections.Generic; using AlicizaX.Runtime; namespace AlicizaX.UI.Runtime { internal sealed partial class UIManager { private readonly Dictionary m_CacheWindow = new(); private void CacheWindow(UIMetadata uiMetadata, bool force) { if (uiMetadata == null || uiMetadata.View == null) { Log.Error(" ui not exist!"); return; } if (force || uiMetadata.CacheTime == 0) { uiMetadata.Dispose(); return; } RemoveFromCache(uiMetadata.RuntimeTypeHandle); int tiemrId = -1; uiMetadata.View.Holder.transform.SetParent(UICacheLayer); if (uiMetadata.CacheTime > 0) { tiemrId = _timerManager.AddTimer(OnTimerDiposeWindow, uiMetadata.CacheTime, false, true, uiMetadata); } uiMetadata.InCache = true; m_CacheWindow.Add(uiMetadata.RuntimeTypeHandle, (uiMetadata, tiemrId)); } private void OnTimerDiposeWindow(object[] args) { UIMetadata info = args[0] as UIMetadata; info?.Dispose(); RemoveFromCache(info.RuntimeTypeHandle); } private void RemoveFromCache(RuntimeTypeHandle typeHandle) { if (m_CacheWindow.TryGetValue(typeHandle, out var result)) { m_CacheWindow.Remove(typeHandle); result.Item1.InCache = false; if (result.Item2 > 0) { _timerManager.RemoveTimer(result.Item2); } } } } }