43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using Ichni.RhythmGame;
|
|
using Lean.Pool;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Ichni.Editor
|
|
{
|
|
/// <summary>
|
|
/// 处理 float, int, string 类型的 Drawer。
|
|
/// 创建 DynamicUIInputField 并绑定反射路径。
|
|
/// </summary>
|
|
public class InputFieldDrawer : IPropertyDrawer
|
|
{
|
|
public int DefaultSpan => 1;
|
|
public float DefaultHeight => LayoutPacker.DefaultRowHeight;
|
|
|
|
public DynamicUIElement Draw(DrawContext ctx)
|
|
{
|
|
var go = LeanPool.Spawn(ctx.Registry.GetPrefab("inputField"), ctx.Parent);
|
|
var element = go.GetComponent<DynamicUIInputField>();
|
|
|
|
element.Initialize(ctx.Target, ctx.Label, ctx.FieldName);
|
|
DynamicUIElement.DisableNavigation(element.inputField);
|
|
|
|
if (ctx.AutoUpdate && element is IHaveAutoUpdate autoUpdate)
|
|
{
|
|
autoUpdate.SetAutoUpdate(true);
|
|
}
|
|
|
|
if (ctx.ReadOnly)
|
|
{
|
|
element.inputField.interactable = false;
|
|
}
|
|
|
|
int span = ctx.OverrideSpan ?? DefaultSpan;
|
|
float height = ctx.OverrideHeight ?? DefaultHeight;
|
|
element.SetLayoutSize(span * LayoutPacker.TotalRowWidth / LayoutPacker.MaxSpanPerRow, height);
|
|
|
|
return element;
|
|
}
|
|
}
|
|
}
|