Shop System Migration Guide
Overview
The shop system has been updated to use ScriptableObject-based Item assets instead of hardcoded SimpleShopItem data. This allows for better data management, persistence, and easier content creation.
What Changed
Old System (SimpleShopManager)
- Used hardcoded
SimpleShopItem objects created in code
- Items were temporary and lost when the game closed
- Limited flexibility for item properties
New System (ItemShopManager)
- Uses
Item ScriptableObjects that persist as asset files
- Supports
WeaponItem, ArmorItem, and MiscellaneousItem types
- Items can be created and modified in the Unity Inspector
- Items are loaded automatically from the
Resources/Items folder
Migration Steps
1. Run the Migration Tool
In Unity, go to the menu: RPG > Migrate Shop System
This will:
- Convert any
SimpleShopManager components to ItemShopManager
- Preserve existing settings like shop name
- Save the scene automatically
2. Create Sample Items (Optional)
Run: RPG > Create Sample Items
This creates example items including:
- Simple Sword, Simple Bow, Iron Sword (Weapons)
- Leather Armor, Iron Chainmail (Armor)
- Health Potion, Mana Potion, Hemp Rope (Miscellaneous)
3. Verify Setup
Run: RPG > Verify Shop Setup
This checks:
- ItemShopManager components are present
- No old SimpleShopManager components remain
- Items are properly loaded
- UI components are configured
Creating New Items
Via Unity Menu
- Right-click in Project window
- Go to Create > RPG > Items
- Choose Weapon, Armor, or Miscellaneous
- Configure the item properties in the Inspector
- Save the asset in
Assets/Resources/Items/ (or subfolders)
Item Properties
All Items (Base Item class)
- Item Name: Display name
- Description: Item description
- Icon: Item icon sprite
- Model 3D: 3D representation
- Item Type: Weapon, Armor, Consumable, Tool, Accessory, Miscellaneous
- Rarity: Common, Uncommon, Rare, Epic, Legendary
- Cost: Gold, Silver, Copper prices
- Search Tags: Keywords for shop search functionality
Weapon Items
- Min/Max Damage: Damage range
- Range: Attack range
- Weapon Modifier: Bonus to hit
- Attack Speed: Animation speed
- Weapon Type: Sword, Bow, Crossbow, etc.
- Weapon Class Name: Code class to instantiate
Armor Items
- Armor Class: AC bonus
- Attribute Modifiers: STR, DEX, CON, WIS bonuses/penalties
- Armor Type: Light, Medium, Heavy, Shield
- Armor Slot: Head, Chest, Legs, etc.
Miscellaneous Items
- Is Consumable: Whether item is used up
- Is Stackable: Whether items can stack
- Max Stack Size: Maximum stack count
- Health/Mana Restoration: Dice-based or range-based healing
Shop Features
Automatic Item Loading
The ItemShopManager automatically loads all Item ScriptableObjects from:
Assets/Resources/Items/ folder and all subfolders
- Direct
Assets/Resources/ folder (as fallback)
Filtering and Search
- Category Filter: Filter by item type (Weapons, Armor, etc.)
- Search Field: Search by item name, description, or tags
- Combined Filtering: Category and search work together
Purchase System
- Checks if player can afford items
- Handles gold/silver/copper currency conversion
- Updates player money automatically
- Adds purchased items to character inventory (requires inventory system integration)
Integration Notes
Character Inventory
The shop calls AddItemToCustomerInventory(Item item) when items are purchased. You'll need to implement this method based on your inventory system:
private void AddItemToCustomerInventory(Item item)
{
// Example integration:
currentCustomer.inventory.AddItem(item);
// Or if using a different system:
InventoryManager.Instance.AddItemToCharacter(currentCustomer, item);
}
Bank System
The shop uses a Bank helper class for currency operations. The current implementation converts between character money and the bank format automatically.
UI Integration
The shop uses the existing ShopUI.uxml file. Make sure the UIDocument component has this visual tree asset assigned.
File Structure
Assets/
├── Resources/
│ └── Items/
│ ├── Weapons/
│ │ ├── SimpleSword.asset
│ │ ├── SimpleBow.asset
│ │ └── IronSword.asset
│ ├── Armor/
│ │ ├── LeatherArmor.asset
│ │ └── IronChainmail.asset
│ └── Miscellaneous/
│ ├── HealthPotion.asset
│ ├── ManaPotion.asset
│ └── HempRope.asset
├── Scripts/
│ ├── Objects/Items/
│ │ ├── Item.cs (base class)
│ │ ├── WeaponItem.cs
│ │ ├── ArmorItem.cs
│ │ └── MiscellaneousItem.cs
│ ├── UI/
│ │ ├── ItemShopManager.cs (new)
│ │ └── SimpleShopManager.cs (deprecated)
│ └── Editor/
│ ├── CreateSampleItems.cs
│ └── ShopSystemMigrator.cs
Troubleshooting
"No items found" in shop
- Check that items are saved in
Assets/Resources/Items/ or subfolders
- Run RPG > Create Sample Items to create test items
- Run RPG > Verify Shop Setup to check configuration
Shop not opening
- Verify
ItemShopManager component exists in scene
- Check that
UIDocument has ShopUI.uxml assigned
- Ensure
MainTeamSelectScript is updated to use ItemShopManager
Compile errors
- Make sure all old
SimpleShopManager references are updated to ItemShopManager
- Check that the new script files are properly imported
- Verify all required using statements are present
Benefits of New System
- Persistent Data: Items are saved as asset files
- Designer Friendly: Non-programmers can create items in Unity Inspector
- Version Control: Item assets can be tracked in source control
- Modular: Easy to add new item types and properties
- Performance: Items are loaded once at startup
- Flexible: Supports complex item properties and behaviors
Next Steps
- Create your own custom items using the Unity Inspector
- Integrate the shop with your character inventory system
- Add item icons and 3D models to enhance visual presentation
- Consider adding item tooltips and detailed stat displays
- Implement item rarity-based visual effects in the shop UI