跳转至

GFEditorPickOperation

API Reference / Kernel / 类索引

  • 路径:addons/gf/kernel/editor/gf_editor_pick_operation.gd
  • 模块:Kernel
  • 继承:RefCounted
  • API:public
  • 类别:编辑器 API (editor_api)
  • 首次版本:3.17.0

编辑器工具的分阶段拾取操作协议。 用于描述 pick、preview、ready、apply 和 cancel 这类持续交互流程。

成员概览

类型 名称 签名
枚举 State enum State
属性 operation_id var operation_id: StringName = &""
属性 label var label: String = ""
属性 metadata var metadata: Dictionary = {}
方法 begin func begin(context: GFEditorToolContextBase) -> bool:
方法 pick func pick(input_data: Dictionary) -> State:
方法 can_apply func can_apply() -> bool:
方法 apply func apply() -> Dictionary:
方法 cancel func cancel() -> void:
方法 get_state func get_state() -> State:
方法 get_preview func get_preview() -> Dictionary:
方法 get_result func get_result() -> Dictionary:
方法 get_debug_snapshot func get_debug_snapshot() -> Dictionary:
方法 _on_begin func _on_begin(_tool_context: GFEditorToolContextBase) -> void:
方法 _on_pick func _on_pick(_input_data: Dictionary) -> Dictionary:
方法 _on_can_apply func _on_can_apply() -> bool:
方法 _on_apply func _on_apply(_tool_context: GFEditorToolContextBase, result: Dictionary) -> Dictionary:
方法 _on_cancel func _on_cancel(_tool_context: GFEditorToolContextBase) -> void:

枚举

State

  • API:public
enum State { ## 尚未开始。 IDLE, ## 正在拾取。 PICKING, ## 已准备好应用。 READY, ## 已应用。 APPLIED, ## 已取消。 CANCELLED, }

拾取操作状态。

属性

operation_id

  • API:public
var operation_id: StringName = &""

操作稳定标识。

label

  • API:public
var label: String = ""

操作显示名称。

metadata

  • API:public
var metadata: Dictionary = {}

调用方附加元数据。

结构:

  • metadata: Dictionary for caller-defined pick operation metadata.

方法

begin

  • API:public
func begin(context: GFEditorToolContextBase) -> bool:

开始拾取操作。

参数:

名称 说明
context 编辑器工具上下文。

返回:成功开始返回 true。

pick

  • API:public
func pick(input_data: Dictionary) -> State:

输入一次拾取数据。

参数:

名称 说明
input_data 调用方传入的通用拾取数据。

返回:操作状态。

结构:

  • input_data: Dictionary containing tool-specific pick input.

can_apply

  • API:public
func can_apply() -> bool:

检查当前操作是否可应用。

返回:可应用返回 true。

apply

  • API:public
func apply() -> Dictionary:

应用拾取结果。

返回:应用结果字典。

结构:

  • return: Dictionary result produced by _on_apply().

cancel

  • API:public
func cancel() -> void:

取消拾取操作。

get_state

  • API:public
func get_state() -> State:

获取当前状态。

返回:当前操作状态。

get_preview

  • API:public
func get_preview() -> Dictionary:

获取预览数据副本。

返回:预览数据。

结构:

  • return: Dictionary preview data produced by _on_pick().

get_result

  • API:public
func get_result() -> Dictionary:

获取拾取结果副本。

返回:拾取结果。

结构:

  • return: Dictionary result data produced by _on_pick().

get_debug_snapshot

  • API:public
func get_debug_snapshot() -> Dictionary:

获取调试快照。

返回:调试快照字典。

结构:

  • return: Dictionary containing operation_id, label, state, preview, result, and metadata.

_on_begin

  • API:protected
func _on_begin(_tool_context: GFEditorToolContextBase) -> void:

拾取流程开始时调用,供子类重写。

参数:

名称 说明
_tool_context 编辑器工具上下文。

_on_pick

  • API:protected
func _on_pick(_input_data: Dictionary) -> Dictionary:

处理一次拾取输入,供子类重写。

参数:

名称 说明
_input_data 调用方传入的通用拾取数据。

返回:拾取响应字典,可包含 preview、result 和 ready。

结构:

  • _input_data: Dictionary containing tool-specific pick input.
  • return: Dictionary pick response.

_on_can_apply

  • API:protected
func _on_can_apply() -> bool:

判断当前拾取结果是否可以应用,供子类重写。

返回:可应用返回 true。

_on_apply

  • API:protected
func _on_apply(_tool_context: GFEditorToolContextBase, result: Dictionary) -> Dictionary:

应用拾取结果,供子类重写。

参数:

名称 说明
_tool_context 编辑器工具上下文。
result 拾取结果副本。

返回:应用结果字典。

结构:

  • result: Dictionary pick result data.
  • return: Dictionary apply result.

_on_cancel

  • API:protected
func _on_cancel(_tool_context: GFEditorToolContextBase) -> void:

取消拾取流程时调用,供子类重写。

参数:

名称 说明
_tool_context 编辑器工具上下文。