Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

EditorDebuggerPlugin

继承: RefCounted < Object

实现调试器插件的基类。

描述

编辑器调试器插件 EditorDebuggerPlugin 提供了与调试器的编辑器端相关的函数。

要与调试器交互,必须将这个类的实例通过 EditorPlugin.add_debugger_plugin() 添加至编辑器。

添加完成后,会针对该插件可用的每一个编辑器调试器会话 EditorDebuggerSession 回调一次 _setup_session(),后续有新的会话也会进行回调(这些会话在此阶段可能尚未激活)。

你可以通过 get_sessions() 获取所有可用的 EditorDebuggerSession,也可以通过 get_session() 获取特定的会话。

@tool
extends EditorPlugin

class ExampleEditorDebugger extends EditorDebuggerPlugin:

    func _has_capture(capture):
        # 如果想要处理带有“my_plugin:”前缀的消息则返回 true。
        return capture == "my_plugin"

    func _capture(message, data, session_id):
        if message == "my_plugin:ping":
            get_session(session_id).send_message("my_plugin:echo", data)
            return true
        return false

    func _setup_session(session_id):
        # 在调试器会话 UI 中添加新的选项卡,其中包含一个标签。
        var label = Label.new()
        label.name = "Example plugin" # 会显示为选项卡标题
        label.text = "示例插件"
        var session = get_session(session_id)
        # 监听会话开始和停止信号。
        session.started.connect(func (): print("会话已开始"))
        session.stopped.connect(func (): print("会话已停止"))
        session.add_session_tab(label)

var debugger = ExampleEditorDebugger.new()

func _enter_tree():
    add_debugger_plugin(debugger)

func _exit_tree():
    remove_debugger_plugin(debugger)

要在运行的游戏中连接,请使用 EngineDebugger 单例:

extends Node

func _ready():
    EngineDebugger.register_message_capture("my_plugin", _capture)
    EngineDebugger.send_message("my_plugin:ping", ["test"])

func _capture(message, data):
    # 请注意这里不使用“my_plugin:”前缀。
    if message == "echo":
        prints("收到回响:", data)
        return true
    return false

注意:游戏运行时,在编辑器中调用 @GlobalScope.print() 等函数不会输出任何内容,“输出日志”中只会输出游戏中的消息。

方法

void

_breakpoint_set_in_tree(script: Script, line: int, enabled: bool) virtual

void

_breakpoints_cleared_in_tree() virtual

bool

_capture(message: String, data: Array, session_id: int) virtual

void

_goto_script_line(script: Script, line: int) virtual

bool

_has_capture(capture: String) virtual const

void

_setup_session(session_id: int) virtual

EditorDebuggerSession

get_session(id: int)

Array

get_sessions()


方法说明

void _breakpoint_set_in_tree(script: Script, line: int, enabled: bool) virtual 🔗

覆盖此方法以便在编辑器中设置断点时收到通知。


void _breakpoints_cleared_in_tree() virtual 🔗

覆盖此方法以便当编辑器中所有断点被清除时收到通知。


bool _capture(message: String, data: Array, session_id: int) virtual 🔗

覆盖此方法以处理传入的消息。session_id 是接收到消息的 EditorDebuggerSession 的 ID,可以通过 get_session() 获取会话。能够识别消息时,该方法应返回 true


void _goto_script_line(script: Script, line: int) virtual 🔗

覆盖此方法,当在调试器断点面板中单击断点行时收到通知。


bool _has_capture(capture: String) virtual const 🔗

覆盖此方法以启用从调试器接收消息。如果 capture 为“my_message”,则会将所有以“my_message:”开头的消息传递给 _capture() 方法。


void _setup_session(session_id: int) virtual 🔗

覆盖此方法,以在每次新建 EditorDebuggerSession 时收到通知。请注意,在此阶段会话可能处于非活动状态。


EditorDebuggerSession get_session(id: int) 🔗

返回具有给定 idEditorDebuggerSession


Array get_sessions() 🔗

返回该调试器插件当前可用的 EditorDebuggerSession 数组。

注意:数组中的会话可能处于非活动状态,请通过 EditorDebuggerSession.is_active() 检查它们的状态。