How jxng-min/knight-in-dungeon works
Project Type and Purpose
• This is a Unity-based game project with a strong focus on gameplay mechanics (inventory, shop, reinforcement systems) and UI (title, panels, animations).
• Its purpose is to deliver an engaging 2-player arcade environment, featuring various game components such as character equipment, inventory management, shop gacha systems, and reinforcement mechanics.
File Structure
• The project’s core is organized under the Assets directory with multiple subfolders:
• Scenes: Holds the game’s primary scenes (e.g., Title.unity).
• Scripts: Split into modules that reflect different game mechanics:
• “Etc” (common controllers such as TitleCtrl and Singleton classes).
• “Inventory”: Handles items, equipment, tooltips, and inventory slot logic.
• “Item”: Manages core item classes, data managers, and uses Scriptable Objects to define equipment assets.
• “Reinforcement”: Contains logic for game reinforcement mechanics.
• “Shop”: Implements the gacha, prize control, and shop logic.
• Prefabs: Contains preconfigured UI elements like inventory and shop slots.
• Animations: Organized for the Title scene, with panels for inventory, shop, reinforcement, upgrade, etc.
• Images, Sounds, Fonts, and Tiles: Provide the assets needed for visuals and audio.
• StreamingAssets: Contains JSON data (e.g., ItemData.json) which likely serves as a runtime configuration/data layer for item definitions.
• ProjectSettings and Package data: Manage Unity’s configuration and dependencies.
• Game Engine & Runtime:
• Unity Engine acts as the central runtime environment where scenes, assets, and scripts are executed.
• Scene Management:
• Title Scene: Entry point and main menu, triggered by TitleCtrl.cs, which transitions to other game states.
• Modules & Managers (within Scripts):
• Object Manager / Singleton Pattern: Centralized management of game objects available to multiple modules.
• Inventory System: Includes classes for InventoryBase, EquipmentInventory, ItemInventory, InventorySlot, and InventoryTooltip; interacts with inventory UI (prefabs and animations).
• Item System: Item.cs and related data managers, using Scriptable Objects as defined in asset folders to load equipment data.
• Shop System: Implements the gacha mechanism (Gacha.cs, GachaSlot.cs, PrizeCtrl.cs) for item acquisition.
• Reinforcement System: Reinforcer.cs controls mechanics for upgrading or “reinforcing” player attributes or equipment.
• UI/Animation Layer:
• Panels for Inventory, Shop, Reinforcement, and Upgrade with associated animations (Open and Close animations and Animation Controllers).
• Toggle controls for switching game states or panels (Game Toggle, Inventory Toggle, etc.).
• Data Layer:
• JSON data in StreamingAssets provides external configuration that the Item Data Manager reads at runtime.
Relationships and Interactions
• The Title scene orchestrates transitions to various game systems. For instance, the TitleCtrl.cs may trigger UI panels.
• The Inventory, Shop, and Reinforcement modules communicate with their respective UI elements through prefabs and animation controllers.
• The ItemDataManager uses Scriptable Objects (seen in the “Item/Scriptable Objects” folder) and the JSON file to load item definitions into the game.
• Central managers (using the Singleton pattern) coordinate between modules ensuring that state changes or data updates (like inventory modifications) are reflected across systems.
Architectural Patterns and Design Principles
• Modular Design: Each gameplay aspect (inventory, shop, reinforcement) is separated into its own folder with dedicated scripts to promote separation of concerns.
• Use of Scriptable Objects: For data management and decoupling item definitions from code.
• Singleton Pattern: For central object management, ensuring that managers can be accessed globally.
• MVC-Like Separation: While Unity projects tend to mix view and logic, you still see clear separation with UI controllers, data managers, and gameplay logic scripts.
• Asset-Driven Architecture: Large folders for images, animations, and prefabs indicate an approach where assets drive visual and interactive aspects of the game.