Games Inventory Systems C# C# Harness Tested (Unity Stubs)

Unity C# Stackable Inventory Container

Data-driven Unity C# inventory system using ScriptableObject item definitions, stack merging, slot capacity limits, and change events.

ID: games/unity-inventory-system Version: 1.0.0 License: MIT Framework: Unity 2022+ / Unity 6

Architecture & Runtime Preview

Unity 2022+ / Unity 6

Unity C# ScriptableObject + container component — inspect source tabs and attach InventoryContainer to a player GameObject.

  1. 1ItemDefinition (ScriptableObject: Id, MaxStack)
  2. 2InventoryContainer.TryAdd(item, count) -> merge existing stacks -> allocate free slots
  3. 3OnInventoryChanged event -> UI Slot Grid
Example Project Integration: Copy into Assets/Scripts/Inventory/ inside a Unity project.

Source Code (2 files)

ItemDefinition.cs · csharp
using UnityEngine;

namespace OtterLibrary.Inventory
{
    [CreateAssetMenu(menuName = "Otter Library/Item Definition")]
    public sealed class ItemDefinition : ScriptableObject
    {
        public string ItemId = "potion_health";
        public string DisplayName = "Health Potion";
        [Min(1)] public int MaxStack = 10;
    }
}

Installation & Usage

Copy ItemDefinition.cs and InventoryContainer.cs into Assets/Scripts/Inventory/ in your Unity project.

Create item assets via Right-Click -> Create -> Otter Library -> Item Definition, attach InventoryContainer to a GameObject, and call TryAdd / TryConsume.