This project features a basic item inventory and Minecraft-style crafting system. Players can manage items and combine them in crafting slots to create new ones. It’s built for easy expansion, allowing developers to quickly add new recipes.
It checks for matching recipes from crafting input slots and generates output items accordingly.
Project Highlights
1. Customizable ItemSlot Interaction
Reusable event & condition logic.
Easily extendable via ItemSlot inheritance.
How It Works
The ItemSlot class serves as the foundation of a flexible, modular framework for slot interactions.
public class ItemSlot : MonoBehaviour, IPointerClickHandler{ public virtual void OnPointerClick(PointerEventData eventData) { if (eventData.button == PointerEventData.InputButton.Left) { if (ItemOnSlotAndCursor()) { if (!SlotAndCursorSameItem()) SwapItem(); else StackAllItemCursorToSlot(); } else if (ItemOnSlotAndNoCursor()) { PickItem(); } else if (ItemOnNoSlotAndCursor()) { PlaceItem(); } } else if (eventData.button == PointerEventData.InputButton.Right) { if (ItemOnSlotAndCursor()) { if (!SlotAndCursorSameItem()) SwapItem(); else StackOneItemCursorToSlot(); } else if (ItemOnSlotAndNoCursor()) { PickHalfOfItem(); } else if (ItemOnNoSlotAndCursor()) { DropOneItemCursorToSlot(); } } }}
The virtual void OnPointerClick() method defines how the slot responds to clicks.
Inside this method, pre-built event and condition functions are rearranged like building blocks to create custom behaviors.
This approach allows you to define complex interactions without rewriting core logic.
Derived classes like CraftingOutputSlot simply override this method to customize behavior.
public class CraftingOutputSlot : ItemSlot{ public override void OnPointerClick(PointerEventData eventData) { if (SlotAndCursor()) { if (SlotAndCursorSameItem()) { StackAllItemSlotToCursor(); UpdateInputPanel(); } } else if (SlotAndNoCursor()) { PickItem(); UpdateInputPanel(); } }}
Result: You get clean, reusable logic that’s easy to extend, debug, and customize per slot type.
2. Easy Recipe Setup
Add new recipes via ScriptableObject.
RecipeEditor for intuitive visual configuration.
How It Works
Recipe is a ScriptableObject, edited easily with RecipeEditor’s drag-and-drop interface.
Result: The RecipeEditor allows easy setup of the Recipe, as shown above, making the creation and management of crafting recipes quick, error-resistant, easily configurable, and accessible to both developers and designers.
3. Flexible Crafting Algorithm
Works with any n x n crafting grid.
Shape-normalized recipe matching.
How It Works
The crafting algorithm is very straightforward:
Combine all eItemTypeunique IDs from the craft input slots into a single string, row by row.
If items are placed consecutively on different rows (e.g., like in Sample 3), insert an extra character between the eItemType IDs to preserve the structure.
Remove the outer“Empty slot item type” chars from the created string.
You’ll notice that they all align correctly, even if placed in different locations, as long as their shapes match.
Then, compare the resulting string against all defined recipe strings to check for a match.
Conclusion
This crafting system is flexible, easy to expand, and provides developers with the tools to quickly implement new recipes. Its intuitive design ensures smooth integration and customization for any project.