修改widget
This commit is contained in:
parent
f8f2ea0201
commit
de62954765
@ -1,25 +1,27 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using AlicizaX;
|
using AlicizaX;
|
||||||
|
using AlicizaX.ObjectPool;
|
||||||
|
|
||||||
namespace AlicizaX.UI.Runtime
|
namespace AlicizaX.UI.Runtime
|
||||||
{
|
{
|
||||||
internal static class MetaTypeCache<T> where T : UIBase
|
|
||||||
{
|
|
||||||
public static readonly UIMetadata Metadata;
|
|
||||||
|
|
||||||
static MetaTypeCache()
|
|
||||||
{
|
|
||||||
var type = typeof(T);
|
|
||||||
Metadata = UIMetadataFactory.GetMetadata(type.TypeHandle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class UIMetadataFactory
|
internal static class UIMetadataFactory
|
||||||
{
|
{
|
||||||
private static readonly Dictionary<RuntimeTypeHandle, UIMetadata> UIWindowMetadata = new();
|
private static readonly Dictionary<RuntimeTypeHandle, UIMetadata> UIWindowMetadata = new();
|
||||||
|
|
||||||
internal static UIMetadata GetMetadata(RuntimeTypeHandle handle)
|
private static readonly IObjectPool<UIMetadataObject> m_UIMetadataPool;
|
||||||
|
|
||||||
|
static UIMetadataFactory()
|
||||||
|
{
|
||||||
|
m_UIMetadataPool = ModuleSystem.GetModule<IObjectPoolModule>().CreateSingleSpawnObjectPool<UIMetadataObject>("UI Metadata Pool", 60, 16, 60f, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static UIMetadata GetWindowMetadata<T>()
|
||||||
|
{
|
||||||
|
return GetWindowMetadata(typeof(T).TypeHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static UIMetadata GetWindowMetadata(RuntimeTypeHandle handle)
|
||||||
{
|
{
|
||||||
if (!UIWindowMetadata.TryGetValue(handle, out var meta))
|
if (!UIWindowMetadata.TryGetValue(handle, out var meta))
|
||||||
{
|
{
|
||||||
@ -29,5 +31,51 @@ namespace AlicizaX.UI.Runtime
|
|||||||
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static UIMetadata GetWidgetMetadata<T>()
|
||||||
|
{
|
||||||
|
return GetWidgetMetadata(typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static UIMetadata GetWidgetMetadata(RuntimeTypeHandle handle)
|
||||||
|
{
|
||||||
|
return GetFromPool(Type.GetTypeFromHandle(handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static UIMetadata GetWidgetMetadata(Type type)
|
||||||
|
{
|
||||||
|
return GetFromPool(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
23
Runtime/UI/Constant/UIMetadataObject.cs
Normal file
23
Runtime/UI/Constant/UIMetadataObject.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using AlicizaX.ObjectPool;
|
||||||
|
|
||||||
|
namespace AlicizaX.UI.Runtime
|
||||||
|
{
|
||||||
|
internal class UIMetadataObject : ObjectBase
|
||||||
|
{
|
||||||
|
public static UIMetadataObject Create(UIMetadata target, string name)
|
||||||
|
{
|
||||||
|
UIMetadataObject obj = MemoryPool.Acquire<UIMetadataObject>();
|
||||||
|
obj.Initialize(name, target);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected internal override void Release(bool isShutdown)
|
||||||
|
{
|
||||||
|
UIMetadata metadata = (UIMetadata)Target;
|
||||||
|
if (metadata != null)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Runtime/UI/Constant/UIMetadataObject.cs.meta
Normal file
3
Runtime/UI/Constant/UIMetadataObject.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2212a30398cd4ca28f31f575c65cedd0
|
||||||
|
timeCreated: 1763367776
|
||||||
@ -27,7 +27,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
CreateMetaUI(metaInfo);
|
CreateMetaUI(metaInfo);
|
||||||
await UIHolderFactory.CreateUIResourceAsync(metaInfo, UICacheLayer);
|
await UIHolderFactory.CreateUIResourceAsync(metaInfo, UICacheLayer);
|
||||||
FinalizeShow(metaInfo, userDatas);
|
FinalizeShow(metaInfo, userDatas);
|
||||||
await UpdateVisualState(metaInfo);
|
UpdateVisualState(metaInfo).Forget();
|
||||||
return metaInfo.View;
|
return metaInfo.View;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -43,7 +43,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
{
|
{
|
||||||
if (UIMetaRegistry.TryGet(type, out var metaRegistry))
|
if (UIMetaRegistry.TryGet(type, out var metaRegistry))
|
||||||
{
|
{
|
||||||
UIMetadata metadata = UIMetadataFactory.GetMetadata(metaRegistry.RuntimeTypeHandle);
|
UIMetadata metadata = UIMetadataFactory.GetWindowMetadata(metaRegistry.RuntimeTypeHandle);
|
||||||
return ShowUI(metadata, userDatas);
|
return ShowUI(metadata, userDatas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,23 +52,23 @@ namespace AlicizaX.UI.Runtime
|
|||||||
|
|
||||||
public T ShowUISync<T>(params object[] userDatas) where T : UIBase
|
public T ShowUISync<T>(params object[] userDatas) where T : UIBase
|
||||||
{
|
{
|
||||||
return (T)ShowUIImplSync(MetaTypeCache<T>.Metadata, userDatas);
|
return (T)ShowUIImplSync(UIMetadataFactory.GetWindowMetadata<T>(), userDatas);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask<T> ShowUI<T>(params System.Object[] userDatas) where T : UIBase
|
public async UniTask<T> ShowUI<T>(params System.Object[] userDatas) where T : UIBase
|
||||||
{
|
{
|
||||||
return (T)await ShowUIAsync(MetaTypeCache<T>.Metadata, userDatas);
|
return (T)await ShowUIAsync(UIMetadataFactory.GetWindowMetadata<T>(), userDatas);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void CloseUI<T>(bool force = false) where T : UIBase
|
public void CloseUI<T>(bool force = false) where T : UIBase
|
||||||
{
|
{
|
||||||
CloseUIImpl(MetaTypeCache<T>.Metadata, force).Forget();
|
CloseUIImpl(UIMetadataFactory.GetWindowMetadata<T>(), force).Forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetUI<T>() where T : UIBase
|
public T GetUI<T>() where T : UIBase
|
||||||
{
|
{
|
||||||
return (T)GetUIImpl(MetaTypeCache<T>.Metadata);
|
return (T)GetUIImpl(UIMetadataFactory.GetWindowMetadata<T>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
|
|
||||||
public void CloseUI(RuntimeTypeHandle handle, bool force = false)
|
public void CloseUI(RuntimeTypeHandle handle, bool force = false)
|
||||||
{
|
{
|
||||||
var metadata = UIMetadataFactory.GetMetadata(handle);
|
var metadata = UIMetadataFactory.GetWindowMetadata(handle);
|
||||||
if (metadata.State != UIState.Uninitialized && metadata.State != UIState.Destroying)
|
if (metadata.State != UIState.Uninitialized && metadata.State != UIState.Destroying)
|
||||||
{
|
{
|
||||||
CloseUIImpl(metadata, force).Forget();
|
CloseUIImpl(metadata, force).Forget();
|
||||||
|
|||||||
@ -84,19 +84,19 @@ namespace AlicizaX.UI.Runtime
|
|||||||
protected async UniTask<UIBase> CreateWidgetAsync(string typeName, Transform parent, bool visible = true)
|
protected async UniTask<UIBase> CreateWidgetAsync(string typeName, Transform parent, bool visible = true)
|
||||||
{
|
{
|
||||||
UIMetaRegistry.TryGet(typeName, out var metaRegistry);
|
UIMetaRegistry.TryGet(typeName, out var metaRegistry);
|
||||||
UIMetadata metadata = UIMetadataFactory.GetMetadata(metaRegistry.RuntimeTypeHandle);
|
UIMetadata metadata = UIMetadataFactory.GetWidgetMetadata(metaRegistry.RuntimeTypeHandle);
|
||||||
return await CreateWidgetUIAsync(metadata, parent, visible);
|
return await CreateWidgetUIAsync(metadata, parent, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async UniTask<T> CreateWidgetAsync<T>(Transform parent, bool visible = true) where T : UIBase
|
protected async UniTask<T> CreateWidgetAsync<T>(Transform parent, bool visible = true) where T : UIBase
|
||||||
{
|
{
|
||||||
UIMetadata metadata = MetaTypeCache<T>.Metadata;
|
UIMetadata metadata = UIMetadataFactory.GetWidgetMetadata<T>();
|
||||||
return (T)await CreateWidgetUIAsync(metadata, parent, visible);
|
return (T)await CreateWidgetUIAsync(metadata, parent, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async UniTask<T> CreateWidgetAsync<T>(UIHolderObjectBase holder) where T : UIBase
|
protected async UniTask<T> CreateWidgetAsync<T>(UIHolderObjectBase holder) where T : UIBase
|
||||||
{
|
{
|
||||||
UIMetadata metadata = MetaTypeCache<T>.Metadata;
|
UIMetadata metadata = UIMetadataFactory.GetWidgetMetadata<T>();
|
||||||
metadata.CreateUI();
|
metadata.CreateUI();
|
||||||
UIBase widget = (UIBase)metadata.View;
|
UIBase widget = (UIBase)metadata.View;
|
||||||
widget.BindUIHolder(holder, this);
|
widget.BindUIHolder(holder, this);
|
||||||
@ -112,19 +112,19 @@ namespace AlicizaX.UI.Runtime
|
|||||||
protected UIBase CreateWidgetSync(string typeName, Transform parent, bool visible = true)
|
protected UIBase CreateWidgetSync(string typeName, Transform parent, bool visible = true)
|
||||||
{
|
{
|
||||||
UIMetaRegistry.TryGet(typeName, out var metaRegistry);
|
UIMetaRegistry.TryGet(typeName, out var metaRegistry);
|
||||||
UIMetadata metadata = UIMetadataFactory.GetMetadata(metaRegistry.RuntimeTypeHandle);
|
UIMetadata metadata = UIMetadataFactory.GetWidgetMetadata(metaRegistry.RuntimeTypeHandle);
|
||||||
return CreateWidgetUISync(metadata, parent, visible);
|
return CreateWidgetUISync(metadata, parent, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T CreateWidgetSync<T>(Transform parent, bool visible = true) where T : UIBase
|
protected T CreateWidgetSync<T>(Transform parent, bool visible = true) where T : UIBase
|
||||||
{
|
{
|
||||||
UIMetadata metadata = MetaTypeCache<T>.Metadata;
|
UIMetadata metadata = UIMetadataFactory.GetWidgetMetadata<T>();
|
||||||
return (T)CreateWidgetUISync(metadata, parent, visible);
|
return (T)CreateWidgetUISync(metadata, parent, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T CreateWidgetSync<T>(UIHolderObjectBase holder) where T : UIBase
|
protected T CreateWidgetSync<T>(UIHolderObjectBase holder) where T : UIBase
|
||||||
{
|
{
|
||||||
UIMetadata metadata = MetaTypeCache<T>.Metadata;
|
UIMetadata metadata = UIMetadataFactory.GetWidgetMetadata<T>();
|
||||||
metadata.CreateUI();
|
metadata.CreateUI();
|
||||||
UIBase widget = (UIBase)metadata.View;
|
UIBase widget = (UIBase)metadata.View;
|
||||||
widget.BindUIHolder(holder, this);
|
widget.BindUIHolder(holder, this);
|
||||||
@ -154,6 +154,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
{
|
{
|
||||||
Log.Warning("Already has widget:{0}", meta.View);
|
Log.Warning("Already has widget:{0}", meta.View);
|
||||||
meta.Dispose();
|
meta.Dispose();
|
||||||
|
UIMetadataFactory.ReturnToPool(meta);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,6 +167,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
{
|
{
|
||||||
await widget.InternalClose();
|
await widget.InternalClose();
|
||||||
meta.Dispose();
|
meta.Dispose();
|
||||||
|
UIMetadataFactory.ReturnToPool(meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
// 初始化方法(泛型版本)
|
// 初始化方法(泛型版本)
|
||||||
protected void InitTabVirtuallyView<TTab>(Transform parent = null) where TTab : UIWidget
|
protected void InitTabVirtuallyView<TTab>(Transform parent = null) where TTab : UIWidget
|
||||||
{
|
{
|
||||||
var metadata = MetaTypeCache<TTab>.Metadata;
|
var metadata = UIMetadataFactory.GetWindowMetadata<TTab>();
|
||||||
CacheTabMetadata(metadata, parent);
|
CacheTabMetadata(metadata, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
{
|
{
|
||||||
if (UIMetaRegistry.TryGet(typeName, out var metaRegistry))
|
if (UIMetaRegistry.TryGet(typeName, out var metaRegistry))
|
||||||
{
|
{
|
||||||
var metadata = UIMetadataFactory.GetMetadata(metaRegistry.RuntimeTypeHandle);
|
var metadata = UIMetadataFactory.GetWindowMetadata(metaRegistry.RuntimeTypeHandle);
|
||||||
CacheTabMetadata(metadata, parent);
|
CacheTabMetadata(metadata, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ namespace AlicizaX.UI.Runtime
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var metadata = UIMetadataFactory.GetMetadata(typeHandle);
|
var metadata = UIMetadataFactory.GetWindowMetadata(typeHandle);
|
||||||
var parent = _tabCache[typeHandle];
|
var parent = _tabCache[typeHandle];
|
||||||
|
|
||||||
var widget = await CreateWidgetUIAsync(metadata, parent, false);
|
var widget = await CreateWidgetUIAsync(metadata, parent, false);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user