80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using AlicizaX.Runtime;
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
{
|
|
public sealed class UIMetadata
|
|
{
|
|
public UIBase View { get; private set; }
|
|
public EUIResLoadType LoadType;
|
|
public readonly int UILayer;
|
|
public readonly bool FullScreen;
|
|
public string ResLocation;
|
|
public readonly int CacheTime;
|
|
public readonly Type UILogicType;
|
|
|
|
public bool InCache = false;
|
|
public readonly RuntimeTypeHandle RuntimeTypeHandle;
|
|
|
|
private int NotFlag = 0;
|
|
|
|
public UIState State
|
|
{
|
|
get
|
|
{
|
|
if (View == null) return UIState.Uninitialized;
|
|
return View.State;
|
|
}
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public void CreateUI()
|
|
{
|
|
if (View is null)
|
|
{
|
|
View = (UIBase)Activator.CreateInstance(UILogicType);
|
|
}
|
|
|
|
LoadUIAttribute();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (State != UIState.Uninitialized)
|
|
{
|
|
View.InternalDestroy();
|
|
View = null;
|
|
}
|
|
}
|
|
|
|
public UIMetadata(Type uiType, UILayer layer, bool fullScreen, int cacheTime)
|
|
{
|
|
UILogicType = uiType;
|
|
UILayer = (int)layer;
|
|
FullScreen = fullScreen;
|
|
CacheTime = cacheTime;
|
|
RuntimeTypeHandle = uiType.TypeHandle;
|
|
}
|
|
|
|
public UIMetadata(Type uiType)
|
|
{
|
|
UILogicType = uiType;
|
|
RuntimeTypeHandle = uiType.TypeHandle;
|
|
}
|
|
|
|
private void LoadUIAttribute()
|
|
{
|
|
if (NotFlag == 0)
|
|
{
|
|
NotFlag = 1;
|
|
UIResAttribute resAttribute = Attribute.GetCustomAttribute(View.UIHolderType, typeof(UIResAttribute)) as UIResAttribute;
|
|
if (resAttribute == null)
|
|
throw new GameFrameworkException($"UIHolder: {View.UIHolderType.FullName} UIResAttribute can be null.");
|
|
ResLocation = resAttribute.ResLocation;
|
|
LoadType = resAttribute.ResLoadType;
|
|
}
|
|
}
|
|
}
|
|
}
|