2025-09-05 19:46:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using AlicizaX;
|
|
|
|
|
|
using AlicizaX.Timer.Runtime;
|
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
|
|
|
|
{
|
2026-04-28 18:25:04 +08:00
|
|
|
|
internal sealed partial class UIService : ServiceBase, IUIService, IUIDebugService, IServiceTickable
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-26 16:14:05 +08:00
|
|
|
|
private ITimerService _timerService;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
2026-03-26 16:14:05 +08:00
|
|
|
|
protected override void OnInitialize()
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-26 16:14:05 +08:00
|
|
|
|
protected override void OnDestroyService()
|
|
|
|
|
|
{
|
2026-04-23 20:39:58 +08:00
|
|
|
|
DestroyAllManagedUI();
|
2026-03-26 16:14:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IServiceTickable.Tick(float deltaTime)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
for (int layerIndex = 0; layerIndex < _openUI.Length; layerIndex++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var layer = _openUI[layerIndex];
|
2026-04-28 18:25:04 +08:00
|
|
|
|
int count = layer.Count;
|
2025-11-13 17:46:20 +08:00
|
|
|
|
if (count == 0) continue;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
2026-04-28 18:25:04 +08:00
|
|
|
|
if (layer.Count != count)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 18:25:04 +08:00
|
|
|
|
var window = layer.Items[i];
|
2025-11-13 17:46:20 +08:00
|
|
|
|
if (window.MetaInfo.NeedUpdate)
|
|
|
|
|
|
window.View.InternalUpdate();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UniTask<UIBase>? ShowUI(string type, params object[] userDatas)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (UIMetaRegistry.TryGet(type, out var metaRegistry))
|
|
|
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
|
UIMetadata metadata = UIMetadataFactory.GetWindowMetadata(metaRegistry.RuntimeTypeHandle);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
return ShowUI(metadata, userDatas);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-13 17:46:20 +08:00
|
|
|
|
public T ShowUISync<T>(params object[] userDatas) where T : UIBase
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
|
return (T)ShowUIImplSync(UIMetadataFactory.GetWindowMetadata<T>(), userDatas);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-13 17:46:20 +08:00
|
|
|
|
public async UniTask<T> ShowUI<T>(params System.Object[] userDatas) where T : UIBase
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
|
return (T)await ShowUIAsync(UIMetadataFactory.GetWindowMetadata<T>(), userDatas);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void CloseUI<T>(bool force = false) where T : UIBase
|
|
|
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
|
CloseUIImpl(UIMetadataFactory.GetWindowMetadata<T>(), force).Forget();
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public T GetUI<T>() where T : UIBase
|
|
|
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
|
return (T)GetUIImpl(UIMetadataFactory.GetWindowMetadata<T>());
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private UniTask<UIBase> ShowUI(UIMetadata meta, params System.Object[] userDatas)
|
|
|
|
|
|
{
|
|
|
|
|
|
return ShowUIImplAsync(meta, userDatas);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async UniTask<UIBase> ShowUIAsync(UIMetadata meta, params System.Object[] userDatas)
|
|
|
|
|
|
{
|
|
|
|
|
|
return await ShowUIImplAsync(meta, userDatas);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void CloseUI(RuntimeTypeHandle handle, bool force = false)
|
|
|
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
|
var metadata = UIMetadataFactory.GetWindowMetadata(handle);
|
2025-09-05 19:46:30 +08:00
|
|
|
|
if (metadata.State != UIState.Uninitialized && metadata.State != UIState.Destroying)
|
|
|
|
|
|
{
|
|
|
|
|
|
CloseUIImpl(metadata, force).Forget();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-03-26 16:14:05 +08:00
|
|
|
|
void IUIService.SetTimerService(ITimerService timerService)
|
2025-09-05 19:46:30 +08:00
|
|
|
|
{
|
2026-03-26 16:14:05 +08:00
|
|
|
|
_timerService = timerService;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
2026-04-23 20:19:46 +08:00
|
|
|
|
|
2026-04-23 20:39:58 +08:00
|
|
|
|
private void DestroyAllManagedUI()
|
2026-04-23 20:19:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
for (int layerIndex = 0; layerIndex < _openUI.Length; layerIndex++)
|
|
|
|
|
|
{
|
|
|
|
|
|
LayerData layer = _openUI[layerIndex];
|
|
|
|
|
|
if (layer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 18:25:04 +08:00
|
|
|
|
int count = layer.Count;
|
2026-04-23 20:19:46 +08:00
|
|
|
|
for (int i = count - 1; i >= 0; i--)
|
|
|
|
|
|
{
|
2026-04-28 18:25:04 +08:00
|
|
|
|
UIMetadata meta = layer.Items[i];
|
2026-04-23 20:19:46 +08:00
|
|
|
|
if (meta == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
meta.CancelAsyncOperations();
|
2026-04-23 20:39:58 +08:00
|
|
|
|
meta.DisposeImmediate();
|
2026-04-23 20:19:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 18:25:04 +08:00
|
|
|
|
Array.Clear(layer.Items, 0, layer.Count);
|
|
|
|
|
|
for (int i = 0; i < layer.TypeIdToIndex.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
layer.TypeIdToIndex[i] = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
layer.Count = 0;
|
2026-04-23 20:19:46 +08:00
|
|
|
|
layer.LastFullscreenIndex = -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 18:25:04 +08:00
|
|
|
|
if (m_CacheWindowCount > 0)
|
2026-04-23 20:19:46 +08:00
|
|
|
|
{
|
2026-04-28 18:25:04 +08:00
|
|
|
|
for (int i = m_CacheWindowCount - 1; i >= 0; i--)
|
2026-04-23 20:19:46 +08:00
|
|
|
|
{
|
2026-04-28 18:25:04 +08:00
|
|
|
|
CacheEntry entry = m_CacheWindow[i];
|
2026-04-27 12:06:09 +08:00
|
|
|
|
if (entry.TimerHandle != 0UL && _timerService != null)
|
2026-04-23 20:19:46 +08:00
|
|
|
|
{
|
2026-04-27 12:06:09 +08:00
|
|
|
|
_timerService.RemoveTimer(entry.TimerHandle);
|
2026-04-23 20:19:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
entry.Metadata.InCache = false;
|
|
|
|
|
|
entry.Metadata.CancelAsyncOperations();
|
2026-04-23 20:39:58 +08:00
|
|
|
|
entry.Metadata.DisposeImmediate();
|
2026-04-28 18:25:04 +08:00
|
|
|
|
m_CacheWindow[i] = default;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < m_CacheTypeIdToIndex.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_CacheTypeIdToIndex[i] = -1;
|
2026-04-23 20:19:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-28 18:25:04 +08:00
|
|
|
|
m_CacheWindowCount = 0;
|
2026-04-23 20:19:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-27 12:06:09 +08:00
|
|
|
|
if (m_LastCountDownHandle != 0UL && _timerService != null)
|
2026-04-23 20:19:46 +08:00
|
|
|
|
{
|
2026-04-27 12:06:09 +08:00
|
|
|
|
_timerService.RemoveTimer(m_LastCountDownHandle);
|
|
|
|
|
|
m_LastCountDownHandle = 0UL;
|
2026-04-23 20:19:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (m_LayerBlock != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UnityEngine.Object.Destroy(m_LayerBlock);
|
|
|
|
|
|
m_LayerBlock = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UICacheLayer = null;
|
|
|
|
|
|
UICanvasRoot = null;
|
|
|
|
|
|
UICanvas = null;
|
|
|
|
|
|
UICamera = null;
|
|
|
|
|
|
UIRoot = null;
|
|
|
|
|
|
}
|
2025-09-05 19:46:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|