A Unity shop UI with a shopping cart, category filters, interface-based item data, and a purchase handler for connecting your own inventory and currency systems. The included sample items use ScriptableObjects.
Includes two demo scenes, original and Illustrated Cream UI prefabs, 20 sample items, and debug switches for testing purchase conditions. This repository is a Unity project, not a Unity Package Manager package.
Original UI and purchase-condition debugging
Successful purchase in the Console
- Item icons, names, prices, and configurable quantities.
- Category filters: Other, Weapon, Food, and Tool. Extend
ITEM_TYPEinScripts/Enums.csto add categories; the shop creates tabs for categories present in its item list. - Shopping cart with quantity controls and a running total.
- Money and inventory-capacity checks before checkout.
- A purchase handler supplied when opening the shop, with automatic state-change updates and separate success notifications.
IItemDataitem definitions with per-item inventory stack sizes and sample ScriptableObject assets.- Separate player debug logic and toggle bindings.
The demo simulates funds and inventory capacity. A complete wallet, inventory manager, persistence layer, and real transaction implementation are not included.
- Unity 6000.3.11f1, the version recorded in this project.
- Unity UI (uGUI) and TextMesh Pro for the interface.
- The sample project uses Universal Render Pipeline (URP).
Open the full project to restore its package dependencies from Packages/manifest.json. Other Unity versions and render pipelines have not been verified here.
- Clone or download this repository.
- In Unity Hub, add the repository folder as an existing project.
- Open it with Unity 6000.3.11f1 and let the initial import finish.
- Open
ShopSystemSampleScene.unityfor the original UI orShopSystemIllustratedCream.unityfor the illustrated UI. - Ensure
ShopExamplehas its shop manager and item list assigned, andOpenShopButtonDebugreferences thatShopExampleand the demoPlayerDebug. Keep the GameObject containingShopManagerinactive initially, with the component itself enabled. Enter Play Mode and click OpenShop. - Use the player debug switches to simulate sufficient money and inventory space.
- Add items, change quantities, filter categories, and purchase the cart. Successful demo purchases are logged to the Console.
Path under Assets/ShopSystem/ |
Contents |
|---|---|
Scripts/ |
Shop manager, item/cart views, category buttons, canvas scaling, trade/purchase interfaces, and enums. |
Prefabs/_Base/ |
Original shop and canvas prefabs, shared demo/debug prefabs, and item/cart/category components in comp/. |
Prefabs/IllustratedCream/ |
Illustrated shop and canvas variants, item/cart/category variants, title material, and standalone buttons in Controls/. |
Scenes/ |
Original and Illustrated Cream demo scenes. |
ScriptableObjects/ |
SOShopItemExample.cs and sample item assets in SO_ShopItemExample/. |
Sprites/ |
Shared sample item icons. |
Sprites/IllustratedCream/ |
Illustrated shop backgrounds, panels, buttons, and decorative artwork. |
InventorySystem(differentModule)/ |
IItemData interface and inventorySlotData helpers from a separate inventory module. |
ShopExample.cs |
Holds the shop manager and item list, and opens the shop with a supplied purchase handler. |
OpenShopButtonDebug.cs |
Connects the demo OpenShop button to ShopExample, supplying its assigned PlayerDebug as the purchase handler. |
PlayerDebug.cs |
Simulates player purchase conditions and handles debug purchases. |
PlayerDebugToggleBindings.cs |
Connects the debug switches to player state. |
- In the Project window, choose Create → Scriptable Objects → Inventory → ShopItem.
- Set its name, sprite, price (
Value), category (Type), and maximum stack amount. - Add the asset to the
ShopExampleitem list or pass it toShopManager.OpenShopfrom your own code.
Configure a sample item asset in the Inspector
Assign item assets to the Shop Example Shop Items list
SOShopItemExample extends ScriptableObject and implements:
IItemData: suppliesName,Image, andMaxStackAmmount.IItemTradeable: supplies the integer price throughValue.IItemType: supplies the category throughType.
Custom item classes must implement IItemData and IItemTradeable; they do not need to inherit from a shared ScriptableObject base class. IItemType is optional; items without it appear under Other. Use non-negative prices and positive stack sizes. Pass a non-null array containing non-null, tradeable items to OpenShop.
Pass the items and an IPurchaseHandler each time you open the shop. The optional close callback can restore player controls or other UI state. Assign the shop manager, sample item assets, and demo player in the Inspector:
Start with the GameObject containing ShopManager inactive. OpenShop returns immediately if that GameObject's activeSelf is already true; otherwise it initializes the shop and activates it. Keep the opening button or interaction component outside that inactive GameObject so it can open the shop.
using UnityEngine;
public class OpenShopExample : MonoBehaviour
{
[SerializeField] private ShopManager shop;
[SerializeField] private SOShopItemExample[] items;
[SerializeField] private PlayerDebug player;
public void Open()
{
if (shop.gameObject.activeSelf)
return;
shop.OpenShop(items, player, () => Debug.Log("Shop closed"));
shop.OnPurchaseCompleted += handlePurchaseCompleted;
}
public void Close()
{
shop.CloseShop();
}
private void handlePurchaseCompleted(inventorySlotData[] purchasedItems, int totalPrice)
{
Debug.Log($"Purchased {purchasedItems.Length} item types for {totalPrice}.");
}
}The signature is OpenShop(IItemData[] items, IPurchaseHandler purchaseHandler, UnityAction onShopClosedAction = null). It accepts custom item implementations created at runtime; the concrete ScriptableObject array in this example allows sample assets to be assigned in the Inspector. Replace PlayerDebug with your own component implementing IPurchaseHandler for a real integration.
Opening an inactive shop clears the cart, rebuilds the item and category views, connects the handler's StateChanged event, and activates the shop GameObject. Closing clears the cart, hides the shop, disconnects the handler, clears all OnPurchaseCompleted listeners, and invokes the close callback. Subscribe to completion notifications each time you open a new session, as shown above. To clear the cart while keeping the shop open and the handler connected, call ClearCart().
Calls to OpenShop while the shop GameObject is active are ignored, including calls with different items, a different handler, or a different close callback. The current cart, views, handler, and callbacks stay in place. To replace the item list or handler, call CloseShop() and then OpenShop(...). The example checks the same active state before subscribing so repeated button clicks do not add duplicate completion listeners. With the required Inspector references assigned, closing before opening or closing repeatedly is safe.
Disabling the shop component or its GameObject calls CloseShop through OnDisable. This clears the cart, disconnects the purchase handler, deactivates the shop GameObject, clears completion listeners, and invokes the pending close callback. To reopen, leave the shop GameObject inactive and call OpenShop; manually activating it first causes the open call to be ignored. If you disabled the component itself, re-enable the component before reopening. Ensure the containing Canvas and other parent GameObjects are active when displaying the shop.
Implement IPurchaseHandler on the player or another object responsible for purchases:
public event System.Action StateChanged;
public bool CanPurchaseMoney(int price);
public bool CanPurchaseInventorySlots(inventorySlotData[] cartItems);
public bool TryPurchase(inventorySlotData[] items, int totalPrice);The signatures above describe the contract; provide method bodies in your implementation.
CanPurchaseMoneychecks whether the current funds cover the total price.CanPurchaseInventorySlotschecks whether all cart quantities fit in the inventory.TryPurchaserechecks funds and capacity, then commits the money deduction and item grant together. Returnfalsewithout changing either if the transaction cannot complete.- Raise
StateChangedwhenever funds or inventory capacity change, for example withStateChanged?.Invoke()inside your handler. While the shop is open, the manager automatically refreshes its purchase-condition messages.
Both condition checks must pass. They run when cart data or handler state changes and again when the purchase button is clicked. Keep the condition checks free of transaction side effects; commit changes only in TryPurchase.
Handler registration and removal are private implementation details of ShopManager. Pass the handler to OpenShop and let CloseShop disconnect it.
Empty carts and checkout without a valid handler are rejected. A failed purchase retains the cart; a successful purchase clears it and raises OnPurchaseCompleted(inventorySlotData[] items, int totalPrice). This optional event is for UI, quests, or logging after the transaction, not for deducting money or granting items again.
The provided PlayerDebug simulates the two conditions, raises StateChanged from its debug setters, and logs successful purchases inside TryPurchase. It does not implement an inventory or wallet. In the demo, OpenShopButtonDebug passes it to ShopExample, which opens the manager with its item list and that handler.
Max Quantity Per Item on ShopManager limits the quantity of each item in the cart. The default serialized value is 999. Keep it positive.
IItemData.MaxStackAmmount describes how many items fit in one inventory stack. The sample items use 64 for Other/Food and 1 for Weapons/Tools. A cart row may represent multiple inventory stacks: purchasing three swords requires three slots.
Purchase callbacks receive one inventorySlotData entry per cart item: item exposes its IItemData reference and ammount holds its total requested quantity. Your inventory implementation must distribute that quantity across stacks and check available capacity. See the inventory module documentation for the data helpers and their limitations.
Prices, quantities, and the cart total use int, whose maximum is 2,147,483,647. ShopItem rejects negative prices and counts, and throws if unit price multiplied by quantity exceeds that range. Cart-total addition and quantity addition do not have equivalent overflow checks, and quantity addition occurs before the cart limit is applied. Keep inputs and combined totals within range; the quantity cap alone does not protect every calculation from overflow.
Start by running the included demo, then copy Assets/ShopSystem with its .meta files into your project. Ensure the UI, TextMesh Pro, and current source dependencies are available, and bring over any fonts or other assets referenced by the prefabs.
Use the sample scene as a wiring reference: the shop needs its view prefabs, content transforms, and text fields assigned. Add the shop UI to an active Canvas with a working EventSystem. Keep the shop GameObject inactive initially and call OpenShop with your item list and purchase handler to initialize and show it. Place the opening button or interaction script on a separate active GameObject. If your project already defines equivalent inventory data types, adapt these references before combining the modules to avoid duplicate class names.
This project uses the custom Unity Shop System Source-Available License.
- You may use and modify the system in free or commercial games and applications, including closed-source products.
- You must include the following user-visible credit in your product's credits, About screen, or accompanying user documentation: Uses Unity Shop System by Mateusz Ciszek.
- You may not sell or repackage the system, modified versions, or substantial portions as a reusable asset, plugin, template, library, or toolkit, including in paid bundles.
- Free source sharing is permitted under the same license. Preserve the copyright and license notices when redistributing the system.
The LICENSE contains the full terms. This is source-available software, not OSI-approved open-source software. Third-party materials, including Unity/TextMesh Pro content, fonts, and other third-party assets, retain their own licenses and are not relicensed by this project's license. Preserve their applicable license and attribution notices.

