# CLAUDE.md This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. ## Project Overview Unity game project (no CLI build commands — use the Unity Editor). Two major systems: 1. **Character Controller** — first/third-person movement with animations 2. **Inventory System** — hotbar, drag-drop, crafting, world items, save/load ## Controls | Action | Key | |---|---| | Move | WASD | | Look | Mouse | | Run | Left Shift | | Crouch | C | | Jump | Space | | Pickup | E | | Toggle Inventory | Tab | | Close Inventory | Escape | | Hotbar Select | 1–9 | | Drop Item | Q | ## Architecture ### Input Layer — `PlayerInput` (singleton, DontDestroyOnLoad) All input is centralised in `Assets/charecter-controller/scripts/PlayerInput.cs`. It exposes: - Continuous properties: `MouseX`, `MouseY`, `Horizontal`, `Vertical`, `Crouch`, `Run` - C# events: `OnJumpPressed`, `OnPickupPressed`, `OnToggleInventory`, `OnDropPressed`, `OnHotbarSelect` - `Enabled` flag — set to `false` when the inventory is open to block gameplay input Both `charecter.cs` and `InventoryManager.cs` subscribe to `PlayerInput.Instance` events in `Start()`. Never read `Input.*` directly in new code — go through `PlayerInput`. ### Character Controller — `charecter.cs` - Requires `CharacterController` component - Head-bone / body separation: body yaw tracks camera yaw when moving; head offset is clamped to `±maxHeadYaw` - Bone rotations applied in `LateUpdate` via `ApplyRotations()` - Animator hashes cached as `static readonly int` fields; animator Speed param: 0 = idle, 0.5 = walk, 1 = run - Item pickup radius-cast in `TryPickupNearbyItem()` (2.5 m sphere, closest `WorldItem` wins) ### Inventory System **Singleton chain** (all DontDestroyOnLoad, all auto-created if missing): ``` PlayerInput → InventoryManager → InventoryItemFactory → InventoryEvents ``` **InventoryManager** (`Assets/Inventory/Scripts/InventoryManager.cs`) - `slots[]` (36) = main inventory; `hotbarSlots[]` (9, indices 0-8) - `_itemDict` maps `ItemData.id → ItemData`; rebuilt via `RebuildItemDictionary()` — call this after runtime DB changes - `AddItem()` fill order: existing main stacks → empty main slots → existing hotbar stacks → empty hotbar slots - Save/load: JSON to `Application.persistentDataPath/inventory_save.json`; auto-save on `OnApplicationQuit` **ItemData** — ScriptableObject (`Assets > Create > Inventory > Item`). `id` is auto-assigned as GUID on first `OnEnable`. ItemType enum: `Block, Weapon, Armor, Consumable, Tool, Material`. **InventoryItemFactory** — creates/drops `WorldItem` GameObjects. Needs an `ItemFactoryConfig` ScriptableObject (`Assets > Create > Inventory > Item Factory Config`) assigned in the Inspector for prefab-based spawning; falls back to a primitive cube if no prefab is configured. **CraftingManager** — recipe key is sorted comma-joined ingredient IDs (`"id1,id2,id3"`). Recipes can be added at runtime via `AddRecipe()`. **InventoryUIBuilder** — generates the entire inventory UI programmatically at runtime (Canvas, GridLayoutGroup, Slot components, drag-drop handlers). Assigns `InventoryManager.Instance.slots` and `.hotbarSlots` directly. Do not assign these arrays in the Inspector when using this builder. **InventorySetup** — convenience MonoBehaviour; add to a "GameManager" object to auto-create all managers and UI on scene start. Has an Editor button in the Inspector. Skips creation if `InventoryManager` already exists. ### Scene Setup `Assets/Scenes/SampleScene.unity` is the only scene. Typical hierarchy: - `GameManager` with `InventorySetup` (or manually placed `InventoryManager` + `InventoryUIBuilder`) - Player with `charecter.cs` + `CharacterController` + Animator + head bone reference ### Meta Files Unity requires `.meta` files for all assets — always commit them alongside their assets.