2.8 KiB
2.8 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a Unity game project with two major systems:
- Character Controller - First/third-person movement with animations
- Inventory System - Full inventory with hotbar, drag-drop, crafting, and item generation
Controls
- Movement: WASD
- Look: Mouse
- Run: Left Shift
- Crouch: C
- Jump: Space
- Toggle Inventory: Tab
- Close Inventory: Escape
- Hotbar Selection: 1-9 keys
- Drop Item: Q
Key Files and Structure
Character Controller (Assets/charecter-controller/scripts/)
charecter.cs- Main character controller with movement, jumping, crouching, mouse lookPlayerBuilder.cs- Player setup utilityPlayerBuilderTool.cs- Editor tool for building player objects
Inventory System (Assets/Inventory/Scripts/)
InventoryManager.cs- Core inventory logic (singleton, item operations, save/load)Slot.cs- Individual inventory slot with stacking logicItemData.cs- Item definition (id, name, icon, maxStack, etc.)InventoryEvents.cs- Centralized event system for inventory changesInventoryItemFactory.cs- Creates dropped items in the worldInventoryDragDrop.cs- Drag and drop UI handlingCraftingManager.cs- Recipe-based crafting systemInventoryUIBuilder.cs- Runtime UI generation
Scene
Assets/Scenes/SampleScene.unity- Main test scene
Architecture
Character Controller Design
- Uses Unity's CharacterController component for collision
- Head-body separation: body rotates toward look direction, head can offset within limits
- Animator parameters use
Animator.StringToHashfor performance (Speed, IsMoving, IsCrouching, IsGrounded, Jump) - Physics-based jumping:
v = sqrt(jumpHeight * -2 * gravity) - All movement is framerate-independent with
Time.deltaTime
Inventory Architecture
- Singleton pattern:
InventoryManager.Instancepersists across scenes (DontDestroyOnLoad) - Dual storage: Main inventory (36 slots) + Hotbar (9 slots, indices 0-8)
- Item lookup:
_itemDictdictionary maps item IDs to ItemData - Stacking: Items stack up to
maxStackdefined in ItemData - Events: InventoryEvents provides OnItemAdded, OnItemRemoved, OnInventoryOpened/Closed
Inventory Flow
- Items added via
AddItem(itemId, amount)- tries existing stacks first, then empty slots - Removed via
RemoveItem(itemId, amount)- returns true if successful - Hotbar selection via
SelectHotbarSlot(index)- updates visual selection - Item dropped via
DropSelectedItem()- spawns world object via InventoryItemFactory - JSON serialization via
ExportToJson()/ImportFromJson()
Meta Files
Unity requires .meta files for all assets - always commit them alongside their assets.