TableArea

Abstract MonoBehaviour that defines a trigger-based detection zone on a shop Table. Automatically tracks items entering and leaving the collider bounds by wrapping them as ShopItem instances. Subclass to define specialized table areas (e.g., DisplayArea for item display, TradingArea for trade interactions).

Definition

Namespace: Paragon.Townskeep.ShopSystem Assembly: Townskeep.dll

[RequireComponent(typeof(BoxCollider))]
public abstract class TableArea : MonoBehaviour

Inherits: MonoBehaviour

Remarks

TableArea uses Unity's trigger system to automatically detect items placed on or removed from the table surface. When a collider with an Item component enters the trigger, a ShopItem wrapper is created and added to the tracked list. When it exits, the corresponding wrapper is found and removed.

The BoxCollider (required via [RequireComponent]) should be set as a trigger and sized to match the table surface. Items must have colliders to interact with the trigger zone.

Two Transform reference fields (innerSpot and outerSpot) provide configurable positions used by AI agents for navigation — InnerSpot is where an agent stands behind the table (shopkeeper side), while OuterSpot is where a customer stands.

Known Subclasses

Subclass
Purpose

DisplayArea

Display-only area (no additional behavior)

TradingArea

Supports agent-initiated trade workflows with TradeContext

Quick Lookup

Goal
How

Get all tracked items

tableArea.Items

Add an item manually

tableArea.DisplayItem(item)

Remove an item manually

tableArea.RemoveItem(item)

Get area bounds

tableArea.GetBounds()

Get shopkeeper position

tableArea.InnerSpot

Get customer position

tableArea.OuterSpot

Properties

Items

All ShopItem instances currently tracked in this area. Includes both reserved and unreserved items.

InnerSpot

Configurable transform marking the shopkeeper-side position. Used by AI agents for pathfinding. Set via Inspector.

OuterSpot

Configurable transform marking the customer-side position. Used by AI agents for pathfinding. Set via Inspector.

Fields

boxCollider (protected)

The required trigger collider, set in Awake() via GetComponent<BoxCollider>().

items (protected)

The tracked item list. Visible in Inspector as read-only via Odin attributes.

Methods

DisplayItem

Creates a ShopItem wrapper for the given item and adds it to the tracked list. Called automatically by OnTriggerEnter, but can be called manually.

Parameter
Type
Description

item

Item

The item to track

RemoveItem

Finds the ShopItem wrapping the given item (via implicit conversion comparison) and removes it from the tracked list. Called automatically by OnTriggerExit.

Parameter
Type
Description

item

Item

The item to stop tracking

GetBounds

Returns the world-space bounds of the BoxCollider.

Returns: The boxCollider.bounds.

Extension Points

Subclassing

TableArea is abstract — subclass it to add specialized behavior:

Override/Add
Purpose

Custom methods

Add trade logic, layout logic, etc.

Access items

The protected list is directly accessible in subclasses

Access boxCollider

The protected collider is available for custom bounds logic

Implementation Requirements

When subclassing, you MUST:

  1. Ensure the GameObject has a BoxCollider set as a trigger

You SHOULD:

  • Assign InnerSpot and OuterSpot transforms in the Inspector for AI navigation

  • Avoid overriding Awake() without calling base.Awake() — it initializes the items list and box collider

circle-exclamation

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-exclamation

See Also

  • Table — parent component that queries items

  • ShopItem — the wrapper created for each detected item

  • TableNetwork — network component on the same table

Last updated