GFResourceTableEditor¶
API Reference / Kernel / 类索引
- 路径:
addons/gf/kernel/editor/gf_resource_table_editor.gd - 模块:
Kernel - 继承:
VBoxContainer - API:
public - 类别:编辑器 API (
editor_api) - 首次版本:
3.17.0
通用 Resource 表格编辑控件。 提供资源扫描、属性列提取、表格刷新与单元格提交,不绑定具体资源类型或业务数据。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 信号 | resource_selected |
signal resource_selected(resource: Resource) |
| 信号 | cell_value_committed |
signal cell_value_committed(resource: Resource, property: StringName, old_value: Variant, new_value: Variant) |
| 信号 | resource_save_failed |
signal resource_save_failed(resource: Resource, path: String, error: Error) |
| 信号 | resources_reordered |
signal resources_reordered(resources: Array) |
| 信号 | resource_inserted |
signal resource_inserted(resource: Resource, index: int) |
| 信号 | resource_removed |
signal resource_removed(resource: Resource, index: int) |
| 信号 | resource_filter_changed |
signal resource_filter_changed(query: String, visible_count: int) |
| 常量 | DEFAULT_MAX_SCAN_DEPTH |
const DEFAULT_MAX_SCAN_DEPTH: int = 32 |
| 常量 | DEFAULT_MAX_RESOURCE_PATHS |
const DEFAULT_MAX_RESOURCE_PATHS: int = 10000 |
| 属性 | auto_save_committed_resources |
var auto_save_committed_resources: bool = false |
| 属性 | search_text |
var search_text: String = "" |
| 属性 | sort_property |
var sort_property: StringName = &"" |
| 属性 | sort_ascending |
var sort_ascending: bool = true |
| 方法 | build_export_columns |
static func build_export_columns(resource: Resource, include_read_only: bool = false) -> Array[Dictionary]: |
| 方法 | scan_resource_paths |
static func scan_resource_paths( root_path: String = "res://", extensions: PackedStringArray = PackedStringArray(["tres", "res"]), options: Dictionary = {} ) -> PackedStringArray: |
| 方法 | load_resources_from_paths |
static func load_resources_from_paths(paths: PackedStringArray, script_filter: Script = null) -> Array[Resource]: |
| 方法 | load_resources |
func load_resources(resources: Array[Resource], columns: Array[Dictionary] = []) -> void: |
| 方法 | get_resources |
func get_resources() -> Array[Resource]: |
| 方法 | get_columns |
func get_columns() -> Array[Dictionary]: |
| 方法 | set_search_text |
func set_search_text(query: String) -> void: |
| 方法 | get_visible_row_indices |
func get_visible_row_indices() -> PackedInt32Array: |
| 方法 | get_visible_resource_count |
func get_visible_resource_count() -> int: |
| 方法 | find_resource_index |
func find_resource_index(resource: Resource) -> int: |
| 方法 | sort_by_property |
func sort_by_property(property: StringName = &"", ascending: bool = true) -> void: |
| 方法 | move_resource |
func move_resource(from_index: int, to_index: int) -> bool: |
| 方法 | insert_resource |
func insert_resource(resource: Resource, index: int = -1) -> bool: |
| 方法 | remove_resource |
func remove_resource(row_index: int) -> Resource: |
| 方法 | duplicate_resource |
func duplicate_resource(row_index: int, deep: bool = false, insert_after: bool = true) -> Resource: |
| 方法 | commit_cell_value |
func commit_cell_value(row_index: int, property: StringName, new_value: Variant) -> bool: |
| 方法 | commit_visible_cell_value |
func commit_visible_cell_value(visible_row_index: int, property: StringName, new_value: Variant) -> bool: |
| 方法 | refresh |
func refresh() -> void: |
信号¶
resource_selected¶
- API:
public
表格选中资源时发出。
参数:
| 名称 | 说明 |
|---|---|
resource |
被选中的资源。 |
cell_value_committed¶
- API:
public
signal cell_value_committed(resource: Resource, property: StringName, old_value: Variant, new_value: Variant)
单元格值提交后发出。
参数:
| 名称 | 说明 |
|---|---|
resource |
被修改的资源。 |
property |
被修改的属性名。 |
old_value |
提交前的旧值。 |
new_value |
提交后的新值。 |
结构:
old_value: Variant value before commit.new_value: Variant value after commit.
resource_save_failed¶
- API:
public
自动保存资源失败时发出。
参数:
| 名称 | 说明 |
|---|---|
resource |
保存失败的资源。 |
path |
资源路径。 |
error |
Godot 错误码。 |
resources_reordered¶
- API:
public
资源列表顺序变化后发出。
参数:
| 名称 | 说明 |
|---|---|
resources |
当前资源列表副本。 |
结构:
resources: Array[Resource]
resource_inserted¶
- API:
public
插入资源后发出。
参数:
| 名称 | 说明 |
|---|---|
resource |
被插入的资源。 |
index |
插入索引。 |
resource_removed¶
- API:
public
移除资源后发出。
参数:
| 名称 | 说明 |
|---|---|
resource |
被移除的资源。 |
index |
移除前索引。 |
resource_filter_changed¶
- API:
public
搜索过滤条件变化后发出。
参数:
| 名称 | 说明 |
|---|---|
query |
当前搜索文本。 |
visible_count |
当前可见资源数量。 |
常量¶
DEFAULT_MAX_SCAN_DEPTH¶
- API:
public
默认最大扫描深度。
DEFAULT_MAX_RESOURCE_PATHS¶
- API:
public
默认最大扫描资源路径数量。
属性¶
auto_save_committed_resources¶
- API:
public
提交单元格后是否自动保存已绑定路径的 Resource。
search_text¶
- API:
public
当前搜索过滤文本。为空时显示全部资源。
sort_property¶
- API:
public
当前排序属性;为空时不记录排序属性。
sort_ascending¶
- API:
public
当前排序方向。
方法¶
build_export_columns¶
- API:
public
static func build_export_columns(resource: Resource, include_read_only: bool = false) -> Array[Dictionary]:
基于资源属性列表构建可编辑列声明。
参数:
| 名称 | 说明 |
|---|---|
resource |
示例资源。 |
include_read_only |
是否包含只读属性。 |
返回:列声明列表。
结构:
return: Array of Dictionary column records with name, type, hint, hint_string, usage, and read_only.
scan_resource_paths¶
- API:
public
static func scan_resource_paths( root_path: String = "res://", extensions: PackedStringArray = PackedStringArray(["tres", "res"]), options: Dictionary = {} ) -> PackedStringArray:
递归扫描资源路径。
参数:
| 名称 | 说明 |
|---|---|
root_path |
扫描根路径。 |
extensions |
文件扩展名白名单,不包含点号。 |
options |
可选参数,支持 max_scan_depth 与 max_resource_paths。 |
返回:资源路径列表。
结构:
options: Dictionary with optional max_scan_depth and max_resource_paths.
load_resources_from_paths¶
- API:
public
static func load_resources_from_paths(paths: PackedStringArray, script_filter: Script = null) -> Array[Resource]:
从路径列表加载资源。
参数:
| 名称 | 说明 |
|---|---|
paths |
资源路径列表。 |
script_filter |
可选脚本过滤;只返回附加该脚本或其子类脚本的资源。 |
返回:资源列表。
load_resources¶
- API:
public
加载资源与列声明。
参数:
| 名称 | 说明 |
|---|---|
resources |
Resource 列表。 |
columns |
可选列声明;为空时从第一条资源推导。 |
结构:
columns: Array of Dictionary column records.
get_resources¶
- API:
public
获取当前资源列表拷贝。
返回:资源列表。
get_columns¶
- API:
public
获取当前列声明拷贝。
返回:列声明列表。
结构:
return: Array of Dictionary column records.
set_search_text¶
- API:
public
设置搜索过滤文本。
参数:
| 名称 | 说明 |
|---|---|
query |
搜索文本,会匹配资源标签、路径和当前列值。 |
get_visible_row_indices¶
- API:
public
获取当前可见资源行的原始索引。
返回:可见行索引列表。
get_visible_resource_count¶
- API:
public
获取当前可见资源数量。
返回:可见资源数量。
find_resource_index¶
- API:
public
查找资源在当前列表中的索引。
参数:
| 名称 | 说明 |
|---|---|
resource |
目标资源。 |
返回:资源索引;不存在时返回 -1。
sort_by_property¶
- API:
public
按属性或资源标签排序。
参数:
| 名称 | 说明 |
|---|---|
property |
属性名;为空时按资源标签排序。 |
ascending |
是否升序。 |
move_resource¶
- API:
public
移动资源位置。
参数:
| 名称 | 说明 |
|---|---|
from_index |
原始索引。 |
to_index |
目标索引。 |
返回:移动成功返回 true。
insert_resource¶
- API:
public
插入资源。
参数:
| 名称 | 说明 |
|---|---|
resource |
要插入的资源。 |
index |
插入索引;越界或负数时追加到末尾。 |
返回:插入成功返回 true。
remove_resource¶
- API:
public
移除资源。
参数:
| 名称 | 说明 |
|---|---|
row_index |
资源行索引。 |
返回:被移除的资源;无效索引返回 null。
duplicate_resource¶
- API:
public
复制资源并插入到列表。
参数:
| 名称 | 说明 |
|---|---|
row_index |
资源行索引。 |
deep |
是否深拷贝子资源。 |
insert_after |
为 true 时插入到当前资源之后,否则插入到当前位置。 |
返回:复制出的资源;无效索引返回 null。
commit_cell_value¶
- API:
public
提交单元格值。
参数:
| 名称 | 说明 |
|---|---|
row_index |
资源行索引。 |
property |
属性名。 |
new_value |
新值。 |
返回:提交成功返回 true。
结构:
new_value: Variant value assigned to the resource property.
commit_visible_cell_value¶
- API:
public
func commit_visible_cell_value(visible_row_index: int, property: StringName, new_value: Variant) -> bool:
提交当前可见行的单元格值。
参数:
| 名称 | 说明 |
|---|---|
visible_row_index |
过滤后的可见行索引。 |
property |
属性名。 |
new_value |
新值。 |
返回:提交成功返回 true。
结构:
new_value: Variant value assigned to the resource property.
refresh¶
- API:
public
刷新表格显示。