@@ -331,15 +331,13 @@ a new scene in the editor then edit it.
331331
332332For an editor dock, the root node **must ** be a :ref: `Control <class_Control >`
333333or one of its child classes. For this tutorial, you can create a single button.
334- The name of the root node will also be the name that appears on the dock tab,
335- so be sure to give it a short and descriptive name.
336- Also, don't forget to add some text to your button.
334+ Don't forget to add some text to your button.
337335
338336.. image :: img/making_plugins-my_custom_dock_scene.webp
339337
340338Save this scene as ``my_dock.tscn ``. Now, we need to grab the scene we created
341339then add it as a dock in the editor. For this, you can rely on the function
342- :ref: `add_control_to_dock () <class_EditorPlugin_method_add_control_to_dock >` from the
340+ :ref: `add_dock () <class_EditorPlugin_method_add_dock >` from the
343341:ref: `EditorPlugin <class_EditorPlugin >` class.
344342
345343You need to select a dock position and define the control to add
@@ -361,19 +359,29 @@ The script could look like this:
361359 func _enter_tree():
362360 # Initialization of the plugin goes here.
363361 # Load the dock scene and instantiate it.
364- dock = preload("res://addons/my_custom_dock/my_dock.tscn").instantiate()
362+ var dock_scene = preload("res://addons/my_custom_dock/my_dock.tscn").instantiate()
363+
364+ # Create the dock and add the loaded scene to it.
365+ dock = EditorDock.new()
366+ dock.add_child(dock_scene)
367+
368+ dock.title = "My Dock"
365369
366- # Add the loaded scene to the docks.
367- add_control_to_dock(DOCK_SLOT_LEFT_UL, dock)
368370 # Note that LEFT_UL means the left of the editor, upper-left dock.
371+ dock.default_slot = DOCK_SLOT_LEFT_UL
372+
373+ # Allow the dock to be on the left or right of the editor, and to be made floating.
374+ dock.available_layouts = EditorDock.DOCK_LAYOUT_VERTICAL | EditorDock.DOCK_LAYOUT_FLOATING
375+
376+ add_dock(dock)
369377
370378
371379 func _exit_tree():
372380 # Clean-up of the plugin goes here.
373381 # Remove the dock.
374- remove_control_from_docks (dock)
382+ remove_dock (dock)
375383 # Erase the control from the memory.
376- dock.free ()
384+ dock.queue_free ()
377385
378386 .. code-tab :: csharp
379387
@@ -383,21 +391,35 @@ The script could look like this:
383391 [Tool]
384392 public partial class CustomDock : EditorPlugin
385393 {
386- private Control _dock;
394+ private EditorDock _dock;
387395
388396 public override void _EnterTree()
389397 {
390- _dock = GD.Load<PackedScene>("res://addons/MyCustomDock/MyDock.tscn").Instantiate<Control>();
398+ var _dock_scene = GD.Load<PackedScene>("res://addons/MyCustomDock/MyDock.tscn").Instantiate<Control>();
391399 AddControlToDock(DockSlot.LeftUl, _dock);
400+
401+ // Create the dock and add the loaded scene to it.
402+ _dock = new EditorDock();
403+ _dock.AddChild(dock_scene);
404+
405+ _dock.Title = "My Dock";
406+
407+ // Note that LeftUl means the left of the editor, upper-left dock.
408+ _dock.DefaultSlot = DockSlot.LeftUl;
409+
410+ // Allow the dock to be on the left or right of the editor, and to be made floating.
411+ _dock.AvailableLayouts = DockLayout.Horizontal | DockLayout.Floating;
412+
413+ AddDock(_dock);
392414 }
393415
394416 public override void _ExitTree()
395417 {
396418 // Clean-up of the plugin goes here.
397419 // Remove the dock.
398- RemoveControlFromDocks (_dock);
420+ RemoveDock (_dock);
399421 // Erase the control from the memory.
400- _dock.Free ();
422+ _dock.QueueFree ();
401423 }
402424 }
403425 #endif
0 commit comments