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