AlicizaX/Client/Packages/com.alicizax.unity.ui/Runtime/UI/Constant/UIMetadata.cs

58 lines
1.4 KiB
C#
Raw Normal View History

2025-03-04 18:40:14 +08:00
using System;
using System.Runtime.CompilerServices;
2025-04-28 19:45:45 +08:00
using AlicizaX;
using Cysharp.Threading.Tasks;
2025-03-04 18:40:14 +08:00
namespace AlicizaX.UI.Runtime
{
2025-04-28 19:45:45 +08:00
internal sealed class UIMetadata
2025-03-04 18:40:14 +08:00
{
public UIBase View { get; private set; }
2025-04-28 19:45:45 +08:00
public readonly UIMetaRegistry.UIMetaInfo MetaInfo;
public readonly UIResRegistry.UIResInfo ResInfo;
2025-03-04 18:40:14 +08:00
public readonly Type UILogicType;
public bool InCache = false;
public UIState State
{
get
{
if (View == null) return UIState.Uninitialized;
return View.State;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CreateUI()
{
if (View is null)
{
2025-04-28 19:45:45 +08:00
View = (UIBase)InstanceFactory.CreateInstanceOptimized(UILogicType);
2025-03-04 18:40:14 +08:00
}
}
public void Dispose()
{
2025-04-28 19:45:45 +08:00
DisposeAsync().Forget();
2025-03-04 18:40:14 +08:00
}
2025-04-28 19:45:45 +08:00
private async UniTask DisposeAsync()
2025-03-04 18:40:14 +08:00
{
2025-04-28 19:45:45 +08:00
if (State != UIState.Uninitialized && State != UIState.Destroying)
{
await View.InternalDestroy();
View = null;
}
2025-03-04 18:40:14 +08:00
}
public UIMetadata(Type uiType)
{
UILogicType = uiType;
2025-04-28 19:45:45 +08:00
UIMetaRegistry.TryGet(UILogicType.TypeHandle, out MetaInfo);
UIResRegistry.TryGet(MetaInfo.HolderRuntimeTypeHandle, out ResInfo);
2025-03-04 18:40:14 +08:00
}
}
}