com.alicizax.unity.framework/Runtime/UI/Manager/UIModule.cs
2025-09-05 19:46:30 +08:00

108 lines
3.0 KiB
C#

using System;
using AlicizaX.Resource.Runtime;
using AlicizaX;
using AlicizaX.Timer.Runtime;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace AlicizaX.UI.Runtime
{
internal sealed partial class UIModule : IUIModule
{
public int Priority { get; }
private ITimerModule _timerModule;
void IModule.Dispose()
{
}
void IModuleUpdate.Update(float elapseSeconds, float realElapseSeconds)
{
// 遍历所有层级
for (int layerIndex = 0; layerIndex < _openUI.Length; layerIndex++)
{
var layer = _openUI[layerIndex];
int count = layer.OrderList.Count;
if (count == 0) continue; // 跳过空层级
for (int i = 0; i < count; i++)
{
if (layer.OrderList.Count != count)
{
break;
}
var window = layer.OrderList[i];
window.View.InternalUpdate();
}
}
}
public UniTask<UIBase>? ShowUI(string type, params object[] userDatas)
{
if (UIMetaRegistry.TryGet(type, out var metaRegistry))
{
UIMetadata metadata = UIMetadataFactory.GetMetadata(metaRegistry.RuntimeTypeHandle);
return ShowUI(metadata, userDatas);
}
return null;
}
public UniTask<UIBase> ShowUI<T>(params System.Object[] userDatas) where T : UIBase
{
return ShowUI(MetaTypeCache<T>.Metadata, userDatas);
}
public async UniTask<T> ShowUIAsync<T>(params System.Object[] userDatas) where T : UIBase
{
return (T)await ShowUIAsync(MetaTypeCache<T>.Metadata, userDatas);
}
public void CloseUI<T>(bool force = false) where T : UIBase
{
CloseUIImpl(MetaTypeCache<T>.Metadata, force).Forget();
}
public T GetUI<T>() where T : UIBase
{
return (T)GetUI(MetaTypeCache<T>.Metadata);
}
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)
{
var metadata = UIMetadataFactory.GetMetadata(handle);
if (metadata.State != UIState.Uninitialized && metadata.State != UIState.Destroying)
{
CloseUIImpl(metadata, force).Forget();
}
}
private UIBase GetUI(UIMetadata meta)
{
return (UIBase)GetUIImpl(meta);
}
void IUIModule.SetTimerManager(ITimerModule timerModule)
{
_timerModule = timerModule;
}
}
}