Files
ichni_Creator_Studio/Assets/Scripts/DynamicUI/Drawers/ButtonDrawer.cs
SoulliesOfficial 5fc1392747 新Head
2026-06-09 01:43:55 -04:00

41 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Lean.Pool;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace Ichni.Editor
{
/// <summary>
/// 按钮 Drawer不绑定数据字段。
/// 创建 DynamicUIButton 并绑定 ButtonAction。
/// </summary>
public class ButtonDrawer : IPropertyDrawer
{
public int DefaultSpan => 1;
public float DefaultHeight => LayoutPacker.DefaultRowHeight;
public DynamicUIElement Draw(DrawContext ctx)
{
var go = LeanPool.Spawn(ctx.Registry.GetPrefab("button"), ctx.Parent);
var element = go.GetComponent<DynamicUIButton>();
element.SetText(ctx.Label);
element.Initialize(ctx.Target, ctx.Label, string.Empty);
if (ctx.ButtonAction != null)
{
UnityAction action = () => ctx.ButtonAction();
element.ApplyFunction(action);
}
DynamicUIElement.DisableNavigation(element.button);
int span = ctx.OverrideSpan ?? DefaultSpan;
float height = ctx.OverrideHeight ?? DefaultHeight;
element.SetLayoutSize(span * LayoutPacker.TotalRowWidth / LayoutPacker.MaxSpanPerRow, height);
return element;
}
}
}