2026-03-26 16:14:05 +08:00
|
|
|
using System;
|
2025-09-05 19:46:30 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using AlicizaX;
|
2025-11-17 16:55:06 +08:00
|
|
|
using AlicizaX.ObjectPool;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
internal static class UIMetadataFactory
|
2025-09-05 19:46:30 +08:00
|
|
|
{
|
2025-11-17 16:55:06 +08:00
|
|
|
private static readonly Dictionary<RuntimeTypeHandle, UIMetadata> UIWindowMetadata = new();
|
|
|
|
|
|
|
|
|
|
private static readonly IObjectPool<UIMetadataObject> m_UIMetadataPool;
|
2025-09-05 19:46:30 +08:00
|
|
|
|
2025-11-17 16:55:06 +08:00
|
|
|
static UIMetadataFactory()
|
2025-09-05 19:46:30 +08:00
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
m_UIMetadataPool = AppServices.Require<IObjectPoolService>().CreatePool<UIMetadataObject>(
|
|
|
|
|
new ObjectPoolCreateOptions(
|
|
|
|
|
name: "UI Metadata Pool",
|
|
|
|
|
allowMultiSpawn: false,
|
|
|
|
|
autoReleaseInterval: 60,
|
|
|
|
|
capacity: 16,
|
|
|
|
|
expireTime: 60f,
|
|
|
|
|
priority: 0));
|
2025-09-05 19:46:30 +08:00
|
|
|
}
|
|
|
|
|
|
2025-11-17 16:55:06 +08:00
|
|
|
internal static UIMetadata GetWindowMetadata<T>()
|
|
|
|
|
{
|
|
|
|
|
return GetWindowMetadata(typeof(T).TypeHandle);
|
|
|
|
|
}
|
2025-09-05 19:46:30 +08:00
|
|
|
|
2025-11-17 16:55:06 +08:00
|
|
|
internal static UIMetadata GetWindowMetadata(RuntimeTypeHandle handle)
|
2025-09-05 19:46:30 +08:00
|
|
|
{
|
|
|
|
|
if (!UIWindowMetadata.TryGetValue(handle, out var meta))
|
|
|
|
|
{
|
|
|
|
|
meta = new UIMetadata(Type.GetTypeFromHandle(handle));
|
|
|
|
|
UIWindowMetadata[handle] = meta;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return meta;
|
|
|
|
|
}
|
2025-11-17 16:55:06 +08:00
|
|
|
|
|
|
|
|
internal static UIMetadata GetWidgetMetadata<T>()
|
|
|
|
|
{
|
2025-12-24 20:44:36 +08:00
|
|
|
return GetWidgetMetadata(typeof(T).TypeHandle);
|
2025-11-17 16:55:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal static UIMetadata GetWidgetMetadata(RuntimeTypeHandle handle)
|
|
|
|
|
{
|
|
|
|
|
return GetFromPool(Type.GetTypeFromHandle(handle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static UIMetadata GetFromPool(Type type)
|
|
|
|
|
{
|
|
|
|
|
if (type == null) return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string typeHandleKey = type.FullName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UIMetadataObject metadataObj = m_UIMetadataPool.Spawn(typeHandleKey);
|
|
|
|
|
|
|
|
|
|
if (metadataObj != null && metadataObj.Target != null)
|
|
|
|
|
{
|
|
|
|
|
return (UIMetadata)metadataObj.Target;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UIMetadata newMetadata = new UIMetadata(type);
|
|
|
|
|
UIMetadataObject newMetadataObj = UIMetadataObject.Create(newMetadata, typeHandleKey);
|
|
|
|
|
|
|
|
|
|
m_UIMetadataPool.Register(newMetadataObj, true);
|
|
|
|
|
|
|
|
|
|
return newMetadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static void ReturnToPool(UIMetadata metadata)
|
|
|
|
|
{
|
|
|
|
|
if (metadata == null) return;
|
|
|
|
|
m_UIMetadataPool.Unspawn(metadata);
|
|
|
|
|
}
|
2025-09-05 19:46:30 +08:00
|
|
|
}
|
|
|
|
|
}
|