mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-16 07:33:47 +00:00
Script to visualize connections
This commit is contained in:
parent
a235183c61
commit
0d2302c9fe
9 changed files with 149 additions and 17 deletions
21
addons/ButtonLink/ButtonLink.cs
Normal file
21
addons/ButtonLink/ButtonLink.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#if TOOLS
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
[Tool]
|
||||
public partial class ButtonLink : EditorPlugin
|
||||
{
|
||||
public override void _EnterTree()
|
||||
{
|
||||
// Add a custom type for visualizing the link
|
||||
Script visualizerScript = GD.Load<Script>("res://addons/ButtonLink/DoorButtonVisualizer.cs");
|
||||
AddCustomType("ButtonDoorVisualizer", "Node2D", visualizerScript, null);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
// Remove the custom type when the plugin is disabled
|
||||
RemoveCustomType("ButtonDoorVisualizer");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
33
addons/ButtonLink/DoorButtonVisualizer.cs
Normal file
33
addons/ButtonLink/DoorButtonVisualizer.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class DoorButtonVisualizer : Node2D
|
||||
{
|
||||
[Export] public NodePath TargetPath; // Expose the Target NodePath in the editor
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
if (TargetPath == null || !Engine.IsEditorHint())
|
||||
return;
|
||||
|
||||
// Get the target node
|
||||
Node targetNode = GetNodeOrNull(TargetPath);
|
||||
if (targetNode == null || !(targetNode is Node2D target))
|
||||
return;
|
||||
|
||||
// Draw a line to the target
|
||||
Vector2 start = GlobalPosition;
|
||||
Vector2 end = target.GlobalPosition;
|
||||
|
||||
DrawLine(ToLocal(start), ToLocal(end), Colors.Green, 2);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
// Update the visualization in the editor
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
QueueRedraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
6
addons/ButtonLink/plugin.cfg
Normal file
6
addons/ButtonLink/plugin.cfg
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[plugin]
|
||||
name="Door Button Link"
|
||||
author="Your Name"
|
||||
version="1.0"
|
||||
description="Draws lines between linked buttons and doors in the editor."
|
||||
script="ButtonLink.cs"
|
||||
Loading…
Add table
Add a link
Reference in a new issue