新Head
This commit is contained in:
40
Assets/Scripts/DynamicUI/Drawers/ButtonDrawer.cs
Normal file
40
Assets/Scripts/DynamicUI/Drawers/ButtonDrawer.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user