跳转至

GFEditorTool

API Reference / Kernel / 类索引

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

持续式编辑器交互工具基类。 用于封装需要激活、停用、接收输入并最终产生命令的编辑器工具。 基类只定义生命周期协议,具体绘制和资源修改由子类实现。

成员概览

类型 名称 签名
属性 tool_id var tool_id: StringName = &""
属性 label var label: String = ""
属性 tooltip var tooltip: String = ""
属性 priority var priority: int = 0
属性 metadata var metadata: Dictionary = {}
属性 option_schema var option_schema: GFEditorToolOptionSchemaBase = null
方法 activate func activate(context: GFEditorToolContextBase) -> void:
方法 deactivate func deactivate() -> void:
方法 is_active func is_active() -> bool:
方法 get_context func get_context() -> GFEditorToolContextBase:
方法 set_option_schema func set_option_schema(schema: GFEditorToolOptionSchemaBase, reset_values: bool = true) -> void:
方法 set_tool_option func set_tool_option(option_id: StringName, value: Variant) -> bool:
方法 get_tool_option func get_tool_option(option_id: StringName, default_value: Variant = null) -> Variant:
方法 get_tool_options func get_tool_options() -> Dictionary:
方法 clear_tool_options func clear_tool_options() -> void:
方法 can_handle func can_handle(context: GFEditorToolContextBase) -> bool:
方法 begin_pick_operation func begin_pick_operation(operation: GFEditorPickOperationBase) -> bool:
方法 pick func pick(input_data: Dictionary) -> int:
方法 apply_pick_operation func apply_pick_operation() -> Dictionary:
方法 cancel_pick_operation func cancel_pick_operation() -> void:
方法 get_pick_operation func get_pick_operation() -> GFEditorPickOperationBase:
方法 gui_input func gui_input(event: InputEvent) -> bool:
方法 draw_tool func draw_tool(viewport: Viewport) -> void:
方法 get_debug_snapshot func get_debug_snapshot() -> Dictionary:
方法 _on_activated func _on_activated(_tool_context: GFEditorToolContextBase) -> void:
方法 _on_deactivated func _on_deactivated(_tool_context: GFEditorToolContextBase) -> void:
方法 _handle_gui_input func _handle_gui_input(_event: InputEvent) -> bool:
方法 _draw_tool func _draw_tool(_viewport: Viewport) -> void:

属性

tool_id

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

工具稳定标识。

label

  • API:public
var label: String = ""

工具显示名称。

tooltip

  • API:public
var tooltip: String = ""

工具提示文本。

priority

  • API:public
var priority: int = 0

工具排序权重。

metadata

  • API:public
var metadata: Dictionary = {}

调用方附加元数据。

结构:

  • metadata: Dictionary for caller-defined editor tool metadata.

option_schema

  • API:public
var option_schema: GFEditorToolOptionSchemaBase = null

可选工具选项声明。

方法

activate

  • API:public
func activate(context: GFEditorToolContextBase) -> void:

激活工具。

参数:

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

deactivate

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

停用工具。

is_active

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

工具是否处于激活状态。

返回:激活时返回 true。

get_context

  • API:public
func get_context() -> GFEditorToolContextBase:

获取当前上下文。

返回:当前上下文;未激活时返回 null。

set_option_schema

  • API:public
func set_option_schema(schema: GFEditorToolOptionSchemaBase, reset_values: bool = true) -> void:

设置工具选项声明。

参数:

名称 说明
schema 工具选项声明。
reset_values 是否重置当前选项值。

set_tool_option

  • API:public
func set_tool_option(option_id: StringName, value: Variant) -> bool:

设置工具选项值。

参数:

名称 说明
option_id 选项标识。
value 选项值。

返回:设置成功返回 true。

结构:

  • value: Variant raw option value.

get_tool_option

  • API:public
func get_tool_option(option_id: StringName, default_value: Variant = null) -> Variant:

获取工具选项值。

参数:

名称 说明
option_id 选项标识。
default_value 缺失时返回的默认值。

返回:选项值。

结构:

  • default_value: Variant fallback returned when the option is missing.
  • return: Variant option value copy or fallback.

get_tool_options

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

获取工具选项快照。

返回:选项值副本。

结构:

  • return: Dictionary keyed by option_id, storing option values.

clear_tool_options

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

清空工具选项值。

can_handle

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

工具是否可以处理当前上下文。

参数:

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

返回:可处理时返回 true。

begin_pick_operation

  • API:public
func begin_pick_operation(operation: GFEditorPickOperationBase) -> bool:

开始分阶段拾取操作。

参数:

名称 说明
operation 拾取操作。

返回:成功开始返回 true。

pick

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

向当前拾取操作输入数据。

参数:

名称 说明
input_data 通用拾取数据。

返回:当前拾取状态;没有操作时返回 IDLE。

结构:

  • input_data: Dictionary pick input forwarded to the active pick operation.

apply_pick_operation

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

应用当前拾取操作。

返回:应用结果字典。

结构:

  • return: Dictionary apply result from the active pick operation.

cancel_pick_operation

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

取消当前拾取操作。

get_pick_operation

  • API:public
func get_pick_operation() -> GFEditorPickOperationBase:

获取当前拾取操作。

返回:拾取操作;不存在时返回 null。

gui_input

  • API:public
func gui_input(event: InputEvent) -> bool:

向工具转发输入事件。

参数:

名称 说明
event 输入事件。

返回:true 表示事件已被工具消费。

draw_tool

  • API:public
func draw_tool(viewport: Viewport) -> void:

请求工具绘制调试或交互辅助。

参数:

名称 说明
viewport 绘制目标视口。

get_debug_snapshot

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

获取工具快照。

返回:调试信息字典。

结构:

  • return: Dictionary containing tool_id, label, tooltip, priority, active, options, pick_operation, and metadata.

_on_activated

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

工具激活时调用,供子类重写。

参数:

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

_on_deactivated

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

工具停用时调用,供子类重写。

参数:

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

_handle_gui_input

  • API:protected
func _handle_gui_input(_event: InputEvent) -> bool:

处理 GUI 输入事件,供子类重写。

参数:

名称 说明
_event 输入事件。

返回:事件被消费时返回 true。

_draw_tool

  • API:protected
func _draw_tool(_viewport: Viewport) -> void:

绘制工具辅助内容,供子类重写。

参数:

名称 说明
_viewport 绘制目标视口。