AlicizaX/Client/Packages/com.alicizax.unity.ui/Runtime/UI/UIBase/UIWidget.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2025-03-04 18:40:14 +08:00
using System;
2025-04-28 19:45:45 +08:00
using Cysharp.Threading.Tasks;
2025-03-04 18:40:14 +08:00
using UnityEngine;
using UnityEngine.UI;
namespace AlicizaX.UI.Runtime
{
public abstract class UIWidget : UIBase
{
2025-04-28 19:45:45 +08:00
internal UIBase _parent;
2025-03-04 18:40:14 +08:00
internal UIBase Parent => _parent;
2025-04-28 19:45:45 +08:00
public void Open(params System.Object[] userDatas)
2025-03-04 18:40:14 +08:00
{
2025-04-28 19:45:45 +08:00
RefreshParams(userDatas);
InternalOpen().Forget();
2025-03-04 18:40:14 +08:00
}
public void Close()
{
2025-04-28 19:45:45 +08:00
InternalClose().Forget();
2025-03-04 18:40:14 +08:00
}
public void Destroy()
{
2025-04-28 19:45:45 +08:00
Parent.RemoveWidget(this).Forget();
2025-03-04 18:40:14 +08:00
}
}
public abstract class UIWidget<T> : UIWidget where T : UIHolderObjectBase
{
protected T baseui => (T)Holder;
2025-07-11 21:00:00 +08:00
internal sealed override Type UIHolderType => typeof(T);
2025-04-28 19:45:45 +08:00
2025-07-11 21:00:00 +08:00
internal sealed override void BindUIHolder(UIHolderObjectBase holder, UIBase owner)
2025-04-28 19:45:45 +08:00
{
if (_state != UIState.CreatedUI)
throw new InvalidOperationException("UI already Created");
Holder = holder;
_parent = owner;
_canvas = Holder.transform.GetComponent<Canvas>();
_raycaster = Holder.transform.GetComponent<GraphicRaycaster>();
Depth = owner.Depth + 5;
_state = UIState.Loaded;
}
2025-03-04 18:40:14 +08:00
}
}