SuperAPI AI 工具集

godot-ui

前端与建站

查看项目

更新于 10-15 22:40

技能介绍

用途:在 Godot 4.3+ 中构建用户界面,涵盖 Control 节点、主题、锚点、容器与布局模式,示例以 GDScript 为主并附 C#。

主要能力: 一、Control 基类与层级。Control 是所有 UI 节点基类,使用锚点加偏移定位,具有 size、minimum_size、custom_minimum_size、theme、focus_mode 等属性;UI 节点应置于 CanvasLayer 下以不受相机变换影响。 二、常见容器:VBoxContainer、HBoxContainer、GridContainer、MarginContainer、PanelContainer、ScrollContainer、TabContainer,配合 size_flags_horizontal/vertical 的 SIZE_EXPAND_FILL 与 custom_minimum_size 控制尺寸。 三、锚点与边距:最终位置按 parent_size * anchor + offset 计算;用 set_anchors_and_offsets_preset(Control.PRESET_) 一次设置,内置预设含 Full Rect、Center、Top Left、Top Right、Bottom Center。 四、主题系统:Theme 资源集中管理字体、颜色与 StyleBox;根节点应用并靠继承生效,个别调整用 theme_override_。 五、焦点与导航:focus_mode(FOCUS_NONE/FOCUS_CLICK/FOCUS_ALL)与 focus_neighbor_* 链控制键盘手柄导航,菜单打开时对首个交互元素调用 grab_focus()。 六、常见模式:主菜单、带标签设置页、全屏暂停菜单覆盖层。 七、信号:Button.pressed、Control.gui_input、mouse_entered/mouse_exited,在 ready() 或检查器连接。 八、Godot 4.5+:FoldableContainer 手风琴容器;Label 通过 LabelSettings 叠加多重描边与阴影(RichTextLabel 不支持叠加,仅 BBCode 单层描边)。 九、Godot 4.7 变更:Control.accessibility_live 枚举移至 AccessibilityServer;TabContainer.all_tabs_in_front 废弃;新增 custom_maximum_size、offset_transform*、_get_cursor_shape;PopupMenu 搜索栏;RichTextLabel.add_image()/update_image() 尺寸参数与 ImageUnit 枚举调整。

使用方式:按用途、主要能力、使用方式、适用场景和限制分段;示例代码保留原样,不展开完整长代码。

限制:所有示例仅针对 Godot 4.3+;4.5 与 4.7 特性须在对应版本使用;4.7 部分变更会破坏 C# 二进制或源码兼容性、或使旧 GDScript 名称失效,需按迁移指南处理。