EditorDebuggerPlugin.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="EditorDebuggerPlugin" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
  3. <brief_description>
  4. A base class to implement debugger plugins.
  5. </brief_description>
  6. <description>
  7. [EditorDebuggerPlugin] provides functions related to the editor side of the debugger.
  8. To interact with the debugger, an instance of this class must be added to the editor via [method EditorPlugin.add_debugger_plugin].
  9. Once added, the [method _setup_session] callback will be called for every [EditorDebuggerSession] available to the plugin, and when new ones are created (the sessions may be inactive during this stage).
  10. You can retrieve the available [EditorDebuggerSession]s via [method get_sessions] or get a specific one via [method get_session].
  11. [codeblocks]
  12. [gdscript]
  13. @tool
  14. extends EditorPlugin
  15. class ExampleEditorDebugger extends EditorDebuggerPlugin:
  16. func _has_capture(capture):
  17. # Return true if you wish to handle messages with the prefix "my_plugin:".
  18. return capture == "my_plugin"
  19. func _capture(message, data, session_id):
  20. if message == "my_plugin:ping":
  21. get_session(session_id).send_message("my_plugin:echo", data)
  22. return true
  23. return false
  24. func _setup_session(session_id):
  25. # Add a new tab in the debugger session UI containing a label.
  26. var label = Label.new()
  27. label.name = "Example plugin" # Will be used as the tab title.
  28. label.text = "Example plugin"
  29. var session = get_session(session_id)
  30. # Listens to the session started and stopped signals.
  31. session.started.connect(func (): print("Session started"))
  32. session.stopped.connect(func (): print("Session stopped"))
  33. session.add_session_tab(label)
  34. var debugger = ExampleEditorDebugger.new()
  35. func _enter_tree():
  36. add_debugger_plugin(debugger)
  37. func _exit_tree():
  38. remove_debugger_plugin(debugger)
  39. [/gdscript]
  40. [/codeblocks]
  41. To connect on the running game side, use the [EngineDebugger] singleton:
  42. [codeblocks]
  43. [gdscript]
  44. extends Node
  45. func _ready():
  46. EngineDebugger.register_message_capture("my_plugin", _capture)
  47. EngineDebugger.send_message("my_plugin:ping", ["test"])
  48. func _capture(message, data):
  49. # Note that the "my_plugin:" prefix is not used here.
  50. if message == "echo":
  51. prints("Echo received:", data)
  52. return true
  53. return false
  54. [/gdscript]
  55. [/codeblocks]
  56. [b]Note:[/b] While the game is running, [method @GlobalScope.print] and similar functions [i]called in the editor[/i] do not print anything, the Output Log prints only game messages.
  57. </description>
  58. <tutorials>
  59. </tutorials>
  60. <methods>
  61. <method name="_breakpoint_set_in_tree" qualifiers="virtual">
  62. <return type="void" />
  63. <param index="0" name="script" type="Script" />
  64. <param index="1" name="line" type="int" />
  65. <param index="2" name="enabled" type="bool" />
  66. <description>
  67. Override this method to be notified when a breakpoint is set in the editor.
  68. </description>
  69. </method>
  70. <method name="_breakpoints_cleared_in_tree" qualifiers="virtual">
  71. <return type="void" />
  72. <description>
  73. Override this method to be notified when all breakpoints are cleared in the editor.
  74. </description>
  75. </method>
  76. <method name="_capture" qualifiers="virtual">
  77. <return type="bool" />
  78. <param index="0" name="message" type="String" />
  79. <param index="1" name="data" type="Array" />
  80. <param index="2" name="session_id" type="int" />
  81. <description>
  82. Override this method to process incoming messages. The [param session_id] is the ID of the [EditorDebuggerSession] that received the [param message]. Use [method get_session] to retrieve the session. This method should return [code]true[/code] if the message is recognized.
  83. </description>
  84. </method>
  85. <method name="_goto_script_line" qualifiers="virtual">
  86. <return type="void" />
  87. <param index="0" name="script" type="Script" />
  88. <param index="1" name="line" type="int" />
  89. <description>
  90. Override this method to be notified when a breakpoint line has been clicked in the debugger breakpoint panel.
  91. </description>
  92. </method>
  93. <method name="_has_capture" qualifiers="virtual const">
  94. <return type="bool" />
  95. <param index="0" name="capture" type="String" />
  96. <description>
  97. Override this method to enable receiving messages from the debugger. If [param capture] is "my_message" then messages starting with "my_message:" will be passed to the [method _capture] method.
  98. </description>
  99. </method>
  100. <method name="_setup_session" qualifiers="virtual">
  101. <return type="void" />
  102. <param index="0" name="session_id" type="int" />
  103. <description>
  104. Override this method to be notified whenever a new [EditorDebuggerSession] is created. Note that the session may be inactive during this stage.
  105. </description>
  106. </method>
  107. <method name="get_session">
  108. <return type="EditorDebuggerSession" />
  109. <param index="0" name="id" type="int" />
  110. <description>
  111. Returns the [EditorDebuggerSession] with the given [param id].
  112. </description>
  113. </method>
  114. <method name="get_sessions">
  115. <return type="Array" />
  116. <description>
  117. Returns an array of [EditorDebuggerSession] currently available to this debugger plugin.
  118. [b]Note:[/b] Sessions in the array may be inactive, check their state via [method EditorDebuggerSession.is_active].
  119. </description>
  120. </method>
  121. </methods>
  122. </class>