Skip to content

icsp-xp/DragAndDrop-Utility

Repository files navigation

DragAndDrop Utility

Summary

This project contains a small drag & drop utility for Godot (C#). It provides reusable classes to: create draggable Controls (Draggable), show a drag preview (DragPreview), carry custom payloads (IDragData / DragData) and accept drops in target Controls (DropZone).

Class structure

alt text

How it works

  1. The user begins dragging a Draggable Control.
  2. Godot calls _GetDragData(Vector2 atPosition) on the Draggable.
  3. Draggable calls ConstructDragData() (must be overridden) to obtain an IDragData and creates a DragDataWrapper(nodeAbsolutePath, dragData) returned as a Variant.
  4. If _dragPreviewScene is assigned, Draggable instantiates the preview, initializes it (InitPreview) and registers it with the drag system via SetDragPreview().
  5. Control that act as DropZone inspect the Variant during _CanDropData. If the Variant contains a DragDataWrapper and CanDropDataAt(Vector2) returns true, the DropZone notifies the originating Control (using Draggable.OnDataDropped(IDragData)) through the NodePath in the wrapper.

About

small drag & drop utility for Godot (C#)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages