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

34 lines
877 B
C#
Raw Normal View History

2025-03-04 18:40:14 +08:00
using System;
using System.Collections.Generic;
2025-04-28 19:45:45 +08:00
using AlicizaX;
2025-03-04 18:40:14 +08:00
namespace AlicizaX.UI.Runtime
{
2025-04-28 19:45:45 +08:00
internal static class MetaTypeCache<T> where T : UIBase
2025-03-04 18:40:14 +08:00
{
public static readonly UIMetadata Metadata;
static MetaTypeCache()
{
var type = typeof(T);
2025-04-28 19:45:45 +08:00
Metadata = UIMetadataFactory.GetMetadata(type.TypeHandle);
2025-03-04 18:40:14 +08:00
}
}
2025-03-11 21:03:30 +08:00
internal static class UIMetadataFactory
2025-03-04 18:40:14 +08:00
{
private static readonly Dictionary<RuntimeTypeHandle, UIMetadata> UIWindowMetadata = new();
2025-04-28 19:45:45 +08:00
internal static UIMetadata GetMetadata(RuntimeTypeHandle handle)
2025-03-04 18:40:14 +08:00
{
if (!UIWindowMetadata.TryGetValue(handle, out var meta))
{
2025-04-28 19:45:45 +08:00
meta = new UIMetadata(Type.GetTypeFromHandle(handle));
2025-03-04 18:40:14 +08:00
UIWindowMetadata[handle] = meta;
}
return meta;
}
}
}