Files
my-project/CLAUDE.md
2026-04-15 02:56:11 +05:00

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:

  1. Character Controller - First/third-person movement with animations
  2. 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 look
  • PlayerBuilder.cs - Player setup utility
  • PlayerBuilderTool.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 logic
  • ItemData.cs - Item definition (id, name, icon, maxStack, etc.)
  • InventoryEvents.cs - Centralized event system for inventory changes
  • InventoryItemFactory.cs - Creates dropped items in the world
  • InventoryDragDrop.cs - Drag and drop UI handling
  • CraftingManager.cs - Recipe-based crafting system
  • InventoryUIBuilder.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.StringToHash for 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.Instance persists across scenes (DontDestroyOnLoad)
  • Dual storage: Main inventory (36 slots) + Hotbar (9 slots, indices 0-8)
  • Item lookup: _itemDict dictionary maps item IDs to ItemData
  • Stacking: Items stack up to maxStack defined in ItemData
  • Events: InventoryEvents provides OnItemAdded, OnItemRemoved, OnInventoryOpened/Closed

Inventory Flow

  1. Items added via AddItem(itemId, amount) - tries existing stacks first, then empty slots
  2. Removed via RemoveItem(itemId, amount) - returns true if successful
  3. Hotbar selection via SelectHotbarSlot(index) - updates visual selection
  4. Item dropped via DropSelectedItem() - spawns world object via InventoryItemFactory
  5. JSON serialization via ExportToJson() / ImportFromJson()

Meta Files

Unity requires .meta files for all assets - always commit them alongside their assets.