Demo4 Trading
Examples/Demo4 Trading/TradingDemo.unity
This demo shows transfer between different models, economy, and equipment with fixed slots in one scene.
What The Demo Shows
- player inventory, merchant inventory, and equipment slots
- conversion between different item models
- price and money checks during transfer
MappedSlotInventoryDataBindingfor equipment
How It Is Structured
Data and economy:
Data/PlayerData.csData/MerchantData.csData/TradingEconomyManager.cs
Adapters and conversion:
Adapters/TradableSoAdapter.csAdapters/TradableItemAdapterModelAdapter.csConverters/ModelItemAdapterConverter.csConverters/MerchantItemAdapterConverter.cs
Bindings:
PlayerInventoryDataBinding.csMerchantInventoryDataBinding.csEquipmentInventoryDataBinding.cs
flowchart LR
MerchantData["MerchantData"] <--> MerchantBinding["MerchantInventoryDataBinding"]
MerchantBinding <--> MerchantUI["Merchant Inventory UI"]
PlayerData["PlayerData"] <--> PlayerBinding["PlayerInventoryDataBinding"]
PlayerData <--> EquipmentBinding["EquipmentInventoryDataBinding"]
MerchantBinding -.- Converters["Converters"]
PlayerBinding -.- Converters
MerchantBinding === Domain["TradingHelper / economy checks"]
PlayerBinding === Domain
PlayerBinding <--> PlayerUI["Player Inventory UI"]
EquipmentBinding <--> EquipUI["Equipment UI"]
How It Works
Buying from a merchant:
- Drag starts from the merchant inventory.
- On drop, the converter prepares the item representation for the player inventory.
- Validation checks money and trade restrictions.
- After a successful transfer, bindings update player and merchant data.
- Side effects change gold and related values.
Equipment:
- The item is dragged into a fixed slot.
EquipmentInventoryDataBindingchecksPrimaryAdapterand slot-specificcanDrop.- On success, the concrete field in
PlayerDatasynchronizes with the target slot.
When To Use This Example
- you need different data models on different sides of a transfer
- you need item conversion during transfer
- you need correct exchange between inventories with different adapter models
- you need prices, money, and transfer-time checks
- you need fixed slots on top of a regular inventory
Related pages: