diff --git a/Runtime/UI/Constant/UIMetadata.cs b/Runtime/UI/Constant/UIMetadata.cs index 586c462..63a447b 100644 --- a/Runtime/UI/Constant/UIMetadata.cs +++ b/Runtime/UI/Constant/UIMetadata.cs @@ -71,6 +71,17 @@ namespace AlicizaX.UI.Runtime } } + internal void DisposeImmediate() + { + CancelAsyncOperations(); + + if (State != UIState.Uninitialized && State != UIState.Destroying && View != null) + { + View.InternalDestroyImmediate(); + View = null; + } + } + public UIMetadata(Type uiType) { if (uiType == null) diff --git a/Runtime/UI/Manager/UIService.Block.cs b/Runtime/UI/Manager/UIService.Block.cs index 0a50d99..09b6858 100644 --- a/Runtime/UI/Manager/UIService.Block.cs +++ b/Runtime/UI/Manager/UIService.Block.cs @@ -1,18 +1,17 @@ -using System.Collections.Generic; +using AlicizaX.Timer.Runtime; using UnityEngine; namespace AlicizaX.UI.Runtime { internal sealed partial class UIService { - private GameObject m_LayerBlock; //内部屏蔽对象 显示时之下的所有UI将不可操作 - - private int m_LastCountDownGuid; //倒计时的唯一ID + private GameObject m_LayerBlock; + private int m_LastCountDownGuid; private void InitUIBlock() { m_LayerBlock = new GameObject("LayerBlock"); - var rect = m_LayerBlock.AddComponent(); + RectTransform rect = m_LayerBlock.AddComponent(); m_LayerBlock.AddComponent(); m_LayerBlock.AddComponent(); rect.SetParent(UICanvasRoot); @@ -21,10 +20,6 @@ namespace AlicizaX.UI.Runtime SetLayerBlockOption(false); } - /// - /// 设置UI遮挡 - /// - /// 倒计时/s public void SetUIBlock(float timeDuration) { ITimerService timerService = GetTimerService(); @@ -37,9 +32,6 @@ namespace AlicizaX.UI.Runtime m_LastCountDownGuid = timerService.AddTimer(OnBlockCountDown, timeDuration); } - /// - /// 强制退出UI遮挡 - /// public void ForceExitBlock() { ITimerService timerService = GetTimerService(); @@ -56,23 +48,11 @@ namespace AlicizaX.UI.Runtime RecoverLayerOptionAll(); } - /// - /// 设置UI是否可以操作 - /// 不能提供此API对外操作 - /// 因为有人设置过后就会忘记恢复 - /// 如果你确实需要你可以设置 禁止无限时间 - /// 之后调用恢复操作也可以做到 - /// - /// true = 可以操作 = 屏蔽层会被隐藏 private void SetLayerBlockOption(bool value) { m_LayerBlock.SetActive(value); } - /// - /// 强制恢复层级到可操作状态 - /// 此方法会强制打断倒计时 根据需求调用 - /// public void RecoverLayerOptionAll() { SetLayerBlockOption(false); diff --git a/Runtime/UI/Manager/UIService.Cache.cs b/Runtime/UI/Manager/UIService.Cache.cs index e1e5a14..6084b72 100644 --- a/Runtime/UI/Manager/UIService.Cache.cs +++ b/Runtime/UI/Manager/UIService.Cache.cs @@ -64,7 +64,7 @@ namespace AlicizaX.UI.Runtime if (meta != null) { RemoveFromCache(meta.MetaInfo.RuntimeTypeHandle); - meta.Dispose(); + meta.DisposeImmediate(); } } diff --git a/Runtime/UI/Manager/UIService.cs b/Runtime/UI/Manager/UIService.cs index e61e2c0..968aa9a 100644 --- a/Runtime/UI/Manager/UIService.cs +++ b/Runtime/UI/Manager/UIService.cs @@ -1,5 +1,4 @@ using System; -using AlicizaX.Resource.Runtime; using AlicizaX; using AlicizaX.Timer.Runtime; using Cysharp.Threading.Tasks; @@ -17,7 +16,7 @@ namespace AlicizaX.UI.Runtime protected override void OnDestroyService() { - DestroyAllManagedUI().Forget(); + DestroyAllManagedUI(); } void IServiceTickable.Tick(float deltaTime) @@ -101,7 +100,7 @@ namespace AlicizaX.UI.Runtime _timerService = timerService; } - private async UniTask DestroyAllManagedUI() + private void DestroyAllManagedUI() { for (int layerIndex = 0; layerIndex < _openUI.Length; layerIndex++) { @@ -121,7 +120,7 @@ namespace AlicizaX.UI.Runtime } meta.CancelAsyncOperations(); - await meta.DisposeAsync(); + meta.DisposeImmediate(); } layer.OrderList.Clear(); @@ -152,7 +151,7 @@ namespace AlicizaX.UI.Runtime entry.Metadata.InCache = false; entry.Metadata.CancelAsyncOperations(); - await entry.Metadata.DisposeAsync(); + entry.Metadata.DisposeImmediate(); } m_CacheWindow.Clear(); diff --git a/Runtime/UI/UIBase/UIBase.Widget.cs b/Runtime/UI/UIBase/UIBase.Widget.cs index 383cc88..0c3d6d6 100644 --- a/Runtime/UI/UIBase/UIBase.Widget.cs +++ b/Runtime/UI/UIBase/UIBase.Widget.cs @@ -60,6 +60,34 @@ namespace AlicizaX.UI.Runtime _updateableChildren.Clear(); } + private void DestroyAllChildrenImmediate() + { + var temp = ArrayPool.Shared.Rent(_children.Count); + try + { + int i = 0; + foreach (var kvp in _children) + { + temp[i++] = kvp.Value; + } + + for (int j = 0; j < i; j++) + { + UIMetadata metadata = temp[j]; + metadata.DisposeImmediate(); + UIMetadataFactory.ReturnToPool(metadata); + temp[j] = null; + } + } + finally + { + ArrayPool.Shared.Return(temp, true); + } + + _children.Clear(); + _updateableChildren.Clear(); + } + private void ChildVisible(bool value) { foreach (KeyValuePair kvp in _children) diff --git a/Runtime/UI/UIBase/UIBase.cs b/Runtime/UI/UIBase/UIBase.cs index 5cc464d..29d382e 100644 --- a/Runtime/UI/UIBase/UIBase.cs +++ b/Runtime/UI/UIBase/UIBase.cs @@ -303,6 +303,23 @@ namespace AlicizaX.UI.Runtime _state = UIState.Destroyed; } + internal void InternalDestroyImmediate() + { + if (!UIStateMachine.ValidateTransition(GetType().Name, _state, UIState.Destroying)) + { + return; + } + + InterruptLifecycleTransition(); + _state = UIState.Destroying; + Holder?.OnWindowDestroyEvent?.Invoke(); + DestroyAllChildrenImmediate(); + OnDestroy(); + ReleaseEventListenerProxy(); + Dispose(); + _state = UIState.Destroyed; + } + internal void RefreshParams(params System.Object[] userDatas) { this._userDatas = userDatas; diff --git a/Runtime/UI/UIComponent.cs b/Runtime/UI/UIComponent.cs index 70f4eac..0bf300f 100644 --- a/Runtime/UI/UIComponent.cs +++ b/Runtime/UI/UIComponent.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq.Expressions; using System.Runtime.CompilerServices; -using AlicizaX.Resource.Runtime; using AlicizaX; using AlicizaX.Timer.Runtime; -using Cysharp.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using Object = UnityEngine.Object;