56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AlicizaX.UI.Runtime
|
|
{
|
|
public abstract class UIWidget : UIBase
|
|
{
|
|
private UIBase _parent;
|
|
internal UIBase Parent => _parent;
|
|
|
|
|
|
internal void BindUIHolder(GameObject obj, UIBase parent)
|
|
{
|
|
if (_state != UIState.CreatedUI)
|
|
throw new InvalidOperationException("UI already Created");
|
|
|
|
var holder = (UIHolderObjectBase)obj.GetComponent(UIHolderType);
|
|
|
|
if (holder == null)
|
|
{
|
|
throw new InvalidCastException($"资源{obj.name}上不存在{UIHolderType.FullName}");
|
|
}
|
|
|
|
Holder = holder;
|
|
_parent = parent;
|
|
_canvas = Holder.transform.GetComponent<Canvas>();
|
|
_raycaster = Holder.transform.GetComponent<GraphicRaycaster>();
|
|
Depth = parent.Depth + 5;
|
|
_state = UIState.Loaded;
|
|
}
|
|
|
|
|
|
public void Open()
|
|
{
|
|
InternalOpen();
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
InternalClose();
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
Parent.RemoveWidget(this);
|
|
}
|
|
}
|
|
|
|
public abstract class UIWidget<T> : UIWidget where T : UIHolderObjectBase
|
|
{
|
|
protected T baseui => (T)Holder;
|
|
internal override Type UIHolderType => typeof(T);
|
|
}
|
|
}
|