UIDragObject - jimdroberts/FishMMO GitHub Wiki
UIDragObject
is a UI component in the FishMMO client that handles the dragging of UI elements, such as items or skills. It provides visual feedback while dragging, manages reference data, and handles drop logic for inventory and other draggable objects.
-
public const long NULL_REFERENCE_ID
Constant representing a null reference ID for drag objects.
-
public Image Icon
The icon image displayed while dragging.
-
public long ReferenceID
The reference ID associated with the dragged object.
-
public ReferenceButtonType Type
The type of reference button (e.g., inventory, skill, etc.).
-
public LayerMask LayerMask
Layer mask used for raycasting when dropping items.
-
public float DropDistance
Maximum distance for drop raycast.
-
void Update()
Per-frame update for drag object. Handles drag visuals and drop logic.
-
public void SetReference(Sprite icon, long referenceID, ReferenceButtonType type)
Sets the reference data for the drag object and positions it at the mouse cursor. Parameters: Sprite icon – Sprite to display while dragging; long referenceID – Reference ID for the dragged object; ReferenceButtonType type – Type of reference button.
-
public void Clear()
Clears the drag object state, hides it, and resets reference data.
- Attach
UIDragObject
to a UI GameObject in the Unity Editor. - Assign the
Icon
field in the Inspector to the image used for dragging. - Set the
LayerMask
andDropDistance
as needed for your drop logic.
// Example: Using UIDragObject to drag an inventory item
UIDragObject dragObject = GetComponent<UIDragObject>();
dragObject.Icon = ...; // Assign Image component
dragObject.SetReference(itemIcon, itemID, ReferenceButtonType.Inventory);
// The drag object will follow the mouse and handle drop logic automatically.
- Always assign the
Icon
field in the Inspector to avoid null references. - Use
SetReference
to initialize drag data and show the drag object. - Call
Clear()
to reset and hide the drag object after a drop or cancel action. - Adjust
LayerMask
andDropDistance
for your game's drop mechanics.