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 是接收到 message 的 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) 🔗

返回具有給定 id 的 EditorDebuggerSession。


Array get_sessions() 🔗

返回該除錯器外掛程式目前可用的 EditorDebuggerSession 陣列。

注意:陣列中的會話可能處於非活動狀態,請通過 EditorDebuggerSession.is_active() 檢查它們的狀態。