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 : MonoBehaviourInherits: 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
DisplayArea
Display-only area (no additional behavior)
TradingArea
Supports agent-initiated trade workflows with TradeContext
Quick Lookup
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.
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.
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:
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:
Ensure the GameObject has a
BoxColliderset as a trigger
You SHOULD:
Assign
InnerSpotandOuterSpottransforms in the Inspector for AI navigationAvoid overriding
Awake()without callingbase.Awake()— it initializes the items list and box collider
Awake() is not virtual in this class. If a subclass defines its own Awake(), Unity will call only the subclass version, and the items list and box collider will be null. Use Start() for subclass initialization instead.
Common Pitfalls
BoxCollider must be a trigger
The [RequireComponent] ensures a BoxCollider exists, but it does not set isTrigger = true. The collider must be configured as a trigger in the Inspector for OnTriggerEnter/OnTriggerExit to fire.
Items need colliders
OnTriggerEnter/OnTriggerExit only fire for GameObjects with colliders. Items without colliders will not be detected.
RemoveItem uses implicit conversion for matching
RemoveItem() finds the matching ShopItem via items.Find(shopItem => (Item)shopItem == item), using the implicit conversion operator. This compares by Item reference identity.
Duplicate entries possible
If DisplayItem() is called manually for an item that has also entered the trigger, the item will be tracked twice. There is no duplicate check.
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