Draggable Nodes - CSharpGodotTools/Template GitHub Wiki
[!IMPORTANT]
Area2D
's are not only created forNode2D
's but also forControl
nodes. This can be seen as extra unwanted bloat. This may be fixed in the future so onlyArea2D
's are created forNode2D
's and theGuiinput
event is used forControl
nodes. This is not being tracked in any issue as of writing this.
[!IMPORTANT] Reflection is performance heavy and unnecessary here. This should be refactored so it is no longer an attribute but rather a node component you drag onto a parent node. The settings would be defined as [Export]'s.
Simply add the [Draggable]
attribute and implement IDraggable
for any Node2D or Control node and it will become draggable in-game.
using Godot;
// Hold to drag and limit movement to vertical axis
[Draggable(DragType.Hold, DragConstraints.Vertical)]
public partial class DraggableNode : Node2D, IDraggable
{
public void OnDragReleased()
{
// Do something with DraggableNode here!
// If the node is not re-parented or queue freed, it will snap back to
// its original position and parent
}
}