Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/track/dope-grid.git?path=Packages/com.fullmetalbagel.dope-grid README
Dope Inventory
A high-performance Unity 2D grid inventory system with drag-and-drop support, item rotation, and stacking.
Features
- 2D Grid-Based Inventory: Efficient grid system using span-based bit arrays and unsafe pointers
- Drag & Drop: Intuitive item dragging between multiple inventories with visual feedback
- Item Rotation: Press R while dragging to rotate items (90°/180°/270°)
- Collision Detection: Real-time placement validation using shape overlap checks
- Object Pooling: Minimized GC allocations through pooling of shapes and UI elements
- uGUI Integration: Ready-to-use Unity UI components
Quick Start
Requirements
- Unity 2022.3 or later
Demo Scene
Open Assets/Scenes/Inventory(uGUI).unity to see a working example.
Architecture
Packages
This repository contains two Unity packages:
DopeGrid (com.fullmetalbagel.dope-grid)
Low-level grid shape library providing:
IGridShape<T>: Interface for mutable grid shapes with typed cell valuesImmutableGridShape: Memory-efficient readonly grid shapes using bit arraysIndexedGridBoard: Grid container managing multiple items with collision detection- Grid transformations (rotation, flipping, trimming)
DopeInventory (com.fullmetalbagel.dope-inventory-ugui)
uGUI-based inventory system built on DopeGrid:
IGameInventory/IUIInventory: Inventory model interfaces with GUID-based item trackingInventoryView: Main MonoBehaviour for inventory UIInventoryViewDragController: Drag-and-drop interaction handlingInventoryItemViewPool: Object pooling for UI elements
Key Components
InventoryView (Packages/com.fullmetalbagel.dope-inventory-ugui/Runtime/UI/InventoryView.cs)
Main component orchestrating inventory UI, handling user input, and synchronizing model-view state.
IGameInventory (Packages/com.fullmetalbagel.dope-inventory-ugui/Runtime/Model/IGameInventory.cs)
Core inventory model interface managing item placement, movement, and removal with collision detection.
IndexedGridBoard (Packages/com.fullmetalbagel.dope-grid/Runtime/IndexedGridBoard.cs)
Grid container storing item IDs per cell, providing efficient spatial queries and collision checking.
Development
Running Tests
Unity Tests:
# Open Test Runner in Unity Editor
# Window > General > Test Runner
# Click "Run All" for EditMode or PlayMode tests
.NET Tests (faster, no Unity dependency):
cd dotnet
dotnet test DopeGrid.sln
# With coverage
dotnet test --collect:"XPlat Code Coverage"
# Specific test
dotnet test --filter "FullyQualifiedName~TestName"
Code Style
- C# 10+ with nullable reference types enabled
- Unsafe code and pointers for performance-critical grid operations
- Pure functions marked with
[Pure, MustUseReturnValue] - Strict analyzer rules with
TreatWarningsAsErrors
Project Structure
Packages/
āāā com.fullmetalbagel.dope-grid/ # Low-level grid library
ā āāā Runtime/ # Grid shapes, boards, transformations
ā āāā Editor/ # Editor utilities
āāā com.fullmetalbagel.dope-inventory-ugui/ # Inventory UI system
ā āāā Runtime/
ā ā āāā Model/ # Inventory model layer
ā ā āāā UI/ # UI components
ā ā āāā Input/ # Input abstraction
Assets/
āāā Scenes/ # Demo scenes
āāā Tests/ # Unity test cases
dotnet/
āāā DopeGrid/ # Standalone .NET project (same source)
License
MIT License - see LICENSE for details.
Installs Over Time
Operating Systems
No data yet
Top Countries
No data yet
Git Versions
No data yet
Embed Install Badge
Add an install count badge to your README
[](https://www.pkglnk.dev/pkg/dope-grid)<a href="https://www.pkglnk.dev/pkg/dope-grid"><img src="https://www.pkglnk.dev/badge/dope-grid.svg?style=pkglnk" alt="pkglnk installs"></a>
No comments yet. Be the first!