A modular Unity inventory system with a playable sample scene.
Chinese Version: README.zh-CN.md
Shows opening the backpack, adding items from the sample GUI, and the overall grid-based layout.
Shows drag movement, placement preview, and item rotation during drag.
Shows right-drag split interaction, stack merging, and dropping items outside the backpack.
Shows quick bar binding and slot switching flow.
- Grid-based backpack with multi-size item placement
- Item rotation
- Stackable items
- Unlockable backpack cells
- Quick bar binding and selection
- Mouse wheel quick bar switching
- Basic weight calculation with UI feedback
- Data-driven setup through
ScriptableObject - Runtime access split into focused interfaces for UI and external systems
- Sample scene wired with Unity Input System
InventoryGridhandles placement checks, overlap detection, auto placement, moving, stacking, merging, and splittingPlayerInventorywraps backpack data, quick bar state, weight, and player-facing operationsInventoryManageracts as the default runtime facade and exposes multiple focused interfacesInventoryEventCentrehandles inventory and quick bar related eventsInventorySystemBootstrapcreates the runtime manager and registers static service entry points
IInventoryRuntimefor general inventory accessIInventoryEventSourcefor event registration and dispatchIBackpackReadOnlyfor read-only backpack stateIQuickBarReadOnlyfor read-only quick bar stateIBackpackViewRuntimefor backpack UI placement and binding logicIBackpackCommandRuntimefor advanced commands such as drop, split, and merge
- Backpack panel
- Quick bar panel
- Left-drag full stack movement
- Placement preview
- Item rotation during drag
- Drag item to quick bar slot to bind
- Drag item outside the backpack to drop it
- Drag onto a compatible stack to merge
- Right-drag half a stack as a split interaction
- Demo scene:
Assets/Scenes/SampleScene.unity - Sample input wrapper:
Assets/Scripts/Sample/SampleInventoryInput.cs - Input action asset:
Assets/SampleInventoryInputAction.inputactions - A simple debug GUI is available in the top-left corner for adding items by ID and count
Sample item IDs:
001BlueGem002Health003Monitor004RAM
- Unity
6000.3.9f1 - URP
- Input System
- Open the project in Unity.
- Open
Assets/Scenes/SampleScene.unity. - Enter Play Mode.
- Use the debug GUI in the top-left corner to add items by ID and count.
Tab: open / close backpackR: rotate current dragged item1to0: select quick bar slot- Mouse wheel: switch quick bar selection
- Left drag: move a full stack
- Right drag: drag half of a stack
- Drag outside the backpack: drop items
- Drag onto a compatible stack: merge items
- Drag onto a quick bar slot: bind item to quick bar
- Left drag moves a full stack.
- Right drag starts a half-stack split preview.
- Releasing outside the backpack drops the dragged amount.
- Releasing over a compatible stack merges the dragged amount.
Assets
├── ArtRes # Item and UI art resources
├── Configs # Item, backpack, quick bar, and view configs
├── Prefabs/UI # Backpack and quick bar prefabs
├── Scenes # Sample scene
├── SampleInventoryInputAction.inputactions
└── Scripts
├── Runtime
│ ├── Core # System entry, bootstrap, events, interfaces, shared configs
│ ├── Data # ItemDefinition / ItemDatabase / ItemInstance
│ ├── Inventory
│ │ ├── Backpack # Backpack data and backpack UI
│ │ ├── Internal # Internal grid and manager implementation
│ │ ├── Player # Player inventory wrapper
│ │ └── QuickBar # Quick bar data and UI
│ └── UI # Shared panel base
└── Sample # Sample input and scene controller scripts
The current structure is centered around a small runtime core plus feature-specific layers:
ItemDefinitionstores static item dataItemInstancerepresents a runtime item instancePlacedItemstores item position, size, and rotation inside the gridInventoryGridowns placement rules and low-level grid operationsPlayerInventoryencapsulates player-facing inventory behaviorInventoryManagerexposes a cleaner facade for UI and external systemsInventorySystemBootstrapwires everything together for scene usage
The UI layer is intentionally kept dependent on focused runtime interfaces instead of directly depending on all runtime implementation details.
- Item instance factory or spawn service
- Save / load support
- More specific event types
- Additional gameplay-facing item actions built on top of the current runtime API



