39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
|
|
using Lean.Pool;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace Ichni.Editor
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 提示文本 Drawer,支持静态文本和 Func<string> 动态文本。
|
|||
|
|
/// 创建 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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|