Demo3 Craft
Examples/Demo3 Craft/CraftDemo.unity
This is a slot-indexed inventory and crafting example where UI synchronizes with fixed data arrays instead of a list.
What The Demo Shows
SlotIndexedInventoryDataBinding- crafting table and result slot
- maximum stack limit per slot
CraftResultDataBindingas a custom inventory type for taking the crafting result
How It Is Structured
The central logic point is:
Crafting/CraftingManager.cs
It stores:
_hotbarItems_inventoryItems_craftTableItems- recipe list
- current result and crafting multiplier
UI is split into four independent bindings:
MainInventoryDataBindingHotbarDataBindingCraftTableDataBindingCraftResultDataBinding
How It Works
Regular slots:
- Binding enumerates occupied indices through
GetOccupiedSlots(). AddToSlotData(...)andRemoveFromSlotData(...)callCraftingManagermethods.- On
Awake(), inventories callSetMaxStackSize(CraftingManager.MaxItemsPerSlot)to limit item count per slot.
Crafting:
- Changing the craft table updates
_craftTableItems. CraftingManager.RefreshCraftResult()searches for a matching recipe.CraftResultDataBinding.OnReloadUI()shows the result and configures the drag step.- When the user takes the result,
OnItemRemovedFromUI(...)callsConsumeCraftIngredients(...).
This is a useful example of a read-only slot that does not accept incoming drop, but creates an item based on external logic that can be taken out.
When To Use This Example
- you need an inventory with fixed indices
- you need crafting
- you need an output slot with an effect after extraction