Files
ichni_Creator_Studio/Assets/Scripts/DynamicUI/Drawers/ToggleDrawer.cs
SoulliesOfficial 5fc1392747 新Head
2026-06-09 01:43:55 -04:00

33 lines
999 B
C#

using Ichni.RhythmGame;
using Lean.Pool;
using UnityEngine;
using UnityEngine.UI;
namespace Ichni.Editor
{
/// <summary>
/// 处理 bool 类型的 Drawer。
/// 创建 DynamicUIToggle。
/// </summary>
public class ToggleDrawer : IPropertyDrawer
{
public int DefaultSpan => 1;
public float DefaultHeight => LayoutPacker.DefaultRowHeight;
public DynamicUIElement Draw(DrawContext ctx)
{
var go = LeanPool.Spawn(ctx.Registry.GetPrefab("toggle"), ctx.Parent);
var element = go.GetComponent<DynamicUIToggle>();
element.Initialize(ctx.Target, ctx.Label, ctx.FieldName);
DynamicUIElement.DisableNavigation(element.toggle);
int span = ctx.OverrideSpan ?? DefaultSpan;
float height = ctx.OverrideHeight ?? DefaultHeight;
element.SetLayoutSize(span * LayoutPacker.TotalRowWidth / LayoutPacker.MaxSpanPerRow, height);
return element;
}
}
}