Table of Contents

Class DropZone<T>

Abstract MonoBehaviour base class for Drop Zone areas in a drag-and-drop system. Responds to Unity pointer events (IDropHandler, IPointerEnterHandler, IPointerExitHandler) and delegates acceptance logic to concrete subclasses. Provides visual highlight feedback when a compatible draggable hovers over the zone.

public abstract class DropZone<T> : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler where T : class

Type Parameters

T

The payload type expected by this drop zone. Must match the draggable's type.

Inheritance
DropZone<T>
Implements
IDropHandler
IPointerEnterHandler
IPointerExitHandler

Remarks

Concrete subclasses must implement CanAcceptDrop(T) to filter incoming data and HandleDrop(T, IDraggable<T>) to process accepted drops (e.g. swap inventory slots, update data models). Override PlayDropFeedback() to add audio or particle effects on successful drop.

Fields

OnDropZoneHighlighted

Fired when the zone becomes highlighted.

public UnityEvent<DropZone<T>> OnDropZoneHighlighted

Field Value

UnityEvent<DropZone<T>>

OnDropZoneUnhighlighted

Fired when the zone returns to its normal (unhighlighted) state.

public UnityEvent<DropZone<T>> OnDropZoneUnhighlighted

Field Value

UnityEvent<DropZone<T>>

OnItemDropped

Fired when an item is successfully dropped onto this zone.

public UnityEvent<T> OnItemDropped

Field Value

UnityEvent<T>

OnItemEntered

Fired when a compatible draggable enters the zone's hit area.

public UnityEvent<T> OnItemEntered

Field Value

UnityEvent<T>

OnItemExited

Fired when a draggable exits the zone's hit area.

public UnityEvent<T> OnItemExited

Field Value

UnityEvent<T>

acceptAnyType

protected bool acceptAnyType

Field Value

bool

backgroundImage

protected Image backgroundImage

Field Value

Image

highlightColor

protected Color highlightColor

Field Value

Color

isHighlighted

protected bool isHighlighted

Field Value

bool

normalColor

protected Color normalColor

Field Value

Color

Methods

Awake()

protected virtual void Awake()

CanAcceptDrop(T)

Determines whether this zone accepts the given data payload. Return false to reject the drop silently.

protected abstract bool CanAcceptDrop(T data)

Parameters

data T

The payload carried by the dragged item.

Returns

bool

HandleDrop(T, IDraggable<T>)

Executes the drop logic for an accepted item (e.g. update slot data, trigger game events).

protected abstract void HandleDrop(T data, IDraggable<T> draggable)

Parameters

data T

The accepted payload.

draggable IDraggable<T>

Reference to the IDraggable<T> that was dropped.

HighlightDropZone()

Applies highlight colour to the background image.

protected virtual void HighlightDropZone()

OnDrop(PointerEventData)

public virtual void OnDrop(PointerEventData eventData)

Parameters

eventData PointerEventData

OnPointerEnter(PointerEventData)

public virtual void OnPointerEnter(PointerEventData eventData)

Parameters

eventData PointerEventData

OnPointerExit(PointerEventData)

public virtual void OnPointerExit(PointerEventData eventData)

Parameters

eventData PointerEventData

PlayDropFeedback()

Override to play visual or audio feedback (e.g. particles, sounds) when a drop succeeds.

protected virtual void PlayDropFeedback()

UnhighlightDropZone()

Restores the background image to the normal colour.

protected virtual void UnhighlightDropZone()