Files
ichni_Creator_Studio/Assets/Scripts/DynamicUI/Drawers/HintTextDrawer.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2026-06-09 01:43:55 -04:00
using Lean.Pool;
using UnityEngine;
namespace Ichni.Editor
{
/// <summary>
/// 提示文本 Drawer支持静态文本和 Func&lt;string&gt; 动态文本。
/// 创建 DynamicUIHintText。
/// </summary>
public class HintTextDrawer : IPropertyDrawer
{
public int DefaultSpan => 1;
public float DefaultHeight => LayoutPacker.DefaultRowHeight;
public DynamicUIElement Draw(DrawContext ctx)
{
var go = LeanPool.Spawn(ctx.Registry.GetPrefab("hintText"), ctx.Parent);
var element = go.GetComponent<DynamicUIHintText>();
element.Initialize(ctx.Target, string.Empty, string.Empty);
if (ctx.DynamicText != null)
{
element.SetUpdatingContent(ctx.DynamicText);
}
else if (ctx.StaticText != null)
{
element.SetContent(ctx.StaticText);
}
int span = ctx.OverrideSpan ?? DefaultSpan;
float height = ctx.OverrideHeight ?? DefaultHeight;
element.SetLayoutSize(span * LayoutPacker.TotalRowWidth / LayoutPacker.MaxSpanPerRow, height);
return element;
}
}
}