Add player controller, state management, and input handling
- Implemented PlayerController.cs to manage player movement and actions. - Created PlayerState.cs to track player lives, coins, and key status. - Added CameraFollow.cs for smooth camera movement following the player. - Developed Character.cs as an abstract class for character behavior. - Introduced Enums.cs for defining TreasureType and MapElementType. - Added IDoor interface for door interactions. - Created InputActions.cs for handling player input actions. - Implemented MainMenu.cs for basic menu functionality including play and exit options.
This commit is contained in:
@@ -0,0 +1,309 @@
|
||||
# Architecture Migration - Completion Summary
|
||||
|
||||
## Overview
|
||||
All 10 tasks from the ArchitectureMigration.md plan have been successfully completed. The Gnome's Bounty project now has cleaner architecture, improved separation of concerns, and new core gameplay systems.
|
||||
|
||||
---
|
||||
|
||||
## Changes Made by Task
|
||||
|
||||
### Task 1 ✓ - Normalize UI Manager Naming
|
||||
**Files Changed:**
|
||||
- `UiManager.cs` → `UIManager.cs` (file and class renamed)
|
||||
|
||||
**What Changed:**
|
||||
- Renamed file and class to follow proper C# naming convention (UIManager instead of UiManager)
|
||||
- No breaking changes - internal logic untouched
|
||||
|
||||
---
|
||||
|
||||
### Task 2 ✓ - Separate Hammer Throw Logic and Hammer Projectile Logic
|
||||
**Files Changed:**
|
||||
- `HammerThrower.cs` (refactored)
|
||||
- `Hammer.cs` (refactored)
|
||||
|
||||
**What Changed:**
|
||||
- **HammerThrower.cs**:
|
||||
- Added cooldown system (`_throwCooldown`, `_cooldownTimer`)
|
||||
- Added `CanThrow` property to check if ready
|
||||
- New `TryThrowHammer()` method that respects cooldown
|
||||
- Calls `Hammer.Initialize()` to set direction and speed
|
||||
- Default cooldown: 1.5 seconds
|
||||
|
||||
- **Hammer.cs**:
|
||||
- Added `Initialize(bool facingRight, float speed)` method
|
||||
- Improved collision detection with different object types
|
||||
- Stuns enemies on collision (`OnHitByHammer`)
|
||||
- Breaks BreakableWall objects
|
||||
- Emits noise on impact (integrates with NoiseSystem)
|
||||
- Self-destructs on any collision
|
||||
- Default lifespan: 5 seconds
|
||||
|
||||
---
|
||||
|
||||
### Task 3 ✓ - Add GameManager
|
||||
**File Created:**
|
||||
- `Managers/GameManager.cs`
|
||||
|
||||
**Functionality:**
|
||||
- Singleton managing global game state
|
||||
- Tracks key ownership: `HasKey`, `SetKeyState(bool)`
|
||||
- Tracks treasure count: `TreasureCount`, `AddTreasure(int)`
|
||||
- Events: `OnKeyStateChanged`, `OnTreasureCountChanged`, `OnLevelComplete`
|
||||
- `CompletLevel()` method for level completion
|
||||
- `Reset()` for resetting game state
|
||||
- Debug mode for logging
|
||||
|
||||
**Setup Required:**
|
||||
- Add empty GameObject with GameManager script to scene
|
||||
- Component will auto-persist with `DontDestroyOnLoad`
|
||||
|
||||
---
|
||||
|
||||
### Task 4 ✓ - Add LevelManager
|
||||
**File Created:**
|
||||
- `Managers/LevelManager.cs`
|
||||
|
||||
**Functionality:**
|
||||
- Singleton managing level progression
|
||||
- Tracks key collection and door unlock
|
||||
- Subscribes to GameManager key state changes
|
||||
- `NotifyKeyCollected()` - triggered when player gets key
|
||||
- `NotifyLevelComplete()` - triggered when player exits with key
|
||||
- Events: `OnKeyCollected`, `OnDoorUnlocked`, `OnLevelComplete`
|
||||
- `Reset()` for restarting level
|
||||
- Debug mode for logging
|
||||
|
||||
**Setup Required:**
|
||||
- Add empty GameObject with LevelManager script to scene
|
||||
- In Inspector: Assign Door reference to the `_doorReference` field
|
||||
|
||||
---
|
||||
|
||||
### Task 5 ✓ - Add NoiseSystem
|
||||
**Files Created/Modified:**
|
||||
- `Managers/NoiseSystem.cs` (new)
|
||||
- `EnvironmentObjects/BreakableWall.cs` (updated)
|
||||
- `Hammer.cs` (already includes noise emission)
|
||||
|
||||
**Functionality:**
|
||||
- Singleton noise emission system
|
||||
- `Emit(Vector3 position, float radius)` - emits noise and alerts nearby enemies
|
||||
- Automatically detects enemies on "Enemy" layer
|
||||
- Calls `OnNoise(Vector3 position)` on all nearby enemies
|
||||
- Event: `OnNoiseEmitted` for external systems
|
||||
|
||||
**Setup Required:**
|
||||
- Add empty GameObject with NoiseSystem script to scene
|
||||
- Ensure all enemy GameObject have "Enemy" layer assigned
|
||||
|
||||
---
|
||||
|
||||
### Task 6 ✓ - Add Enemy States to EnemyAI
|
||||
**File Modified:**
|
||||
- `EnemyAI.cs` (completely refactored)
|
||||
|
||||
**Functionality:**
|
||||
- State machine with 4 states: `Patrol`, `Investigate`, `Chase`, `Stunned`
|
||||
- Automatic state transitions based on distance to player
|
||||
- `OnNoise(Vector3 position)` - enters Investigate state
|
||||
- `OnHitByHammer(float stunDuration)` - enters Stunned state and recovers after duration
|
||||
- Configurable ranges and speeds via Inspector
|
||||
- Inspector fields:
|
||||
- `_patrolSpeed`: Speed during patrol
|
||||
- `_patrolRange`: How far to patrol
|
||||
- `_investigateRange`: Range to trigger investigate
|
||||
- `_chaseRange`: Range to trigger chase
|
||||
- `_stunDuration`: How long to stay stunned (default: 1 second)
|
||||
|
||||
**Behavior:**
|
||||
- Patrols back and forth when at peace
|
||||
- Investigates noise sources when hearing sound
|
||||
- Chases player when within range
|
||||
- Recovers from stun and resumes normal behavior
|
||||
|
||||
---
|
||||
|
||||
### Task 7 ✓ - Finalize Hammer Cooldown and Tactical Rules
|
||||
**Files Modified:**
|
||||
- `PlayerController.cs` (updated to use new hammer API)
|
||||
- `HammerThrower.cs` (already includes cooldown)
|
||||
- `Hammer.cs` (already includes tactical rules)
|
||||
|
||||
**What Changed:**
|
||||
- PlayerController now checks `_hammerThrower.CanThrow` before playing throw animation
|
||||
- Calls `TryThrowHammer()` instead of `ThrowHammer()`
|
||||
- Hammer impacts emit noise automatically (configurable)
|
||||
- Hammer stuns enemies without killing them
|
||||
- Hammer breaks only BreakableWall objects
|
||||
- Hammer disappears on impact
|
||||
|
||||
**Tunable Values (Inspector):**
|
||||
- HammerThrower: `_throwCooldown`, `_throwSpeed`
|
||||
- Hammer: `_lifespan`, `_stunDuration`, `_impactNoiseRadius`, `_emitNoiseOnImpact`
|
||||
|
||||
---
|
||||
|
||||
### Task 8 ✓ - Integrate KeyChest with Game State
|
||||
**Files Modified:**
|
||||
- `KeyChest.cs` (updated)
|
||||
- `Chest.cs` (updated)
|
||||
|
||||
**What Changed:**
|
||||
- KeyChest now notifies GameManager when key collected
|
||||
- KeyChest triggers LevelManager to unlock door
|
||||
- Chest properly handles coin and key treasures
|
||||
- Both systems integrate with GameManager for centralized state tracking
|
||||
- Events flow: Chest/KeyChest → GameManager → LevelManager → Door
|
||||
|
||||
---
|
||||
|
||||
### Task 9 ✓ - Improve Door Flow
|
||||
**Files Modified:**
|
||||
- `Door.cs` (refactored)
|
||||
- `DoorInteract.cs` (refactored)
|
||||
|
||||
**What Changed:**
|
||||
- **Door.cs**:
|
||||
- Added explicit `IsLocked` state property
|
||||
- `OpenDoor()` now updates lock state, visuals, and collision
|
||||
- `LockDoor()` can re-lock the door if needed
|
||||
- Event: `OnDoorOpened`
|
||||
|
||||
- **DoorInteract.cs**:
|
||||
- Checks GameManager.HasKey instead of PlayerState
|
||||
- Triggers LevelManager.NotifyLevelComplete() when player exits with key
|
||||
- Prevents multiple completions with `_hasTriggered`
|
||||
- Debug logging for testing
|
||||
|
||||
**Progression Flow:**
|
||||
1. Player collects key → KeyChest → GameManager.SetKeyState(true)
|
||||
2. GameManager triggers → LevelManager.NotifyKeyCollected()
|
||||
3. LevelManager unlocks → Door.OpenDoor()
|
||||
4. Player reaches exit → DoorInteract triggers
|
||||
5. DoorInteract → LevelManager.NotifyLevelComplete()
|
||||
|
||||
---
|
||||
|
||||
### Task 10 ✓ - Folder Cleanup
|
||||
**Folders Created:**
|
||||
- `Assets/Scripts/Player/` - Player-related scripts
|
||||
- `Assets/Scripts/Combat/` - Combat/projectile scripts
|
||||
- `Assets/Scripts/Enemies/` - Enemy AI and spawning
|
||||
- `Assets/Scripts/Environment/` - Environmental objects
|
||||
- `Assets/Scripts/Utilities/` - Helper and utility classes
|
||||
|
||||
**Files Moved:**
|
||||
- **Player/**: PlayerController, HammerThrower, PlayerState
|
||||
- **Combat/**: Hammer
|
||||
- **Enemies/**: EnemyAI, EnemySpawner (renamed from CharacterSpawner)
|
||||
- **Environment/**: BreakableWall, Chest, Door, DoorInteract, KeyChest, MapElements/
|
||||
- **Managers/**: GameManager, LevelManager, NoiseSystem, UIManager, InputManager (unchanged location)
|
||||
- **ScriptableObject/**: TreasureSO, MapElementSO (unchanged location)
|
||||
- **Utilities/**: Character, CameraFollow, IDoor, Enums, InputActions, MainMenu
|
||||
|
||||
---
|
||||
|
||||
## Scene Setup Checklist
|
||||
|
||||
To get the project running after these changes:
|
||||
|
||||
- [ ] **Add GameManager to Scene**
|
||||
- Create empty GameObject
|
||||
- Add `GameManager` component
|
||||
- Leave Debug Mode off for release
|
||||
|
||||
- [ ] **Add LevelManager to Scene**
|
||||
- Create empty GameObject
|
||||
- Add `LevelManager` component
|
||||
- **In Inspector:** Assign the Door GameObject to `_doorReference` field
|
||||
- Leave Debug Mode off for release
|
||||
|
||||
- [ ] **Add NoiseSystem to Scene**
|
||||
- Create empty GameObject
|
||||
- Add `NoiseSystem` component
|
||||
- Ensure all enemy GameObjects have "Enemy" layer assigned
|
||||
- Leave Debug Mode off for release
|
||||
|
||||
- [ ] **Update Enemy Layer**
|
||||
- Select all enemy GameObjects
|
||||
- Set Layer to "Enemy" (create if doesn't exist)
|
||||
- This is critical for NoiseSystem to detect enemies
|
||||
|
||||
- [ ] **Update Scene References**
|
||||
- Check for any scripts that directly reference moved classes
|
||||
- Most will auto-resolve if using GetComponent<>()
|
||||
- Update Inspector if scripts are assigned as references
|
||||
|
||||
- [ ] **Test the Flow:**
|
||||
1. Player throws hammer (with cooldown)
|
||||
2. Hammer hits enemy - enemy should stun and nearby enemies should hear noise
|
||||
3. Player collects key - GameManager updates, door should unlock
|
||||
4. Player exits through door - level completion triggered
|
||||
|
||||
---
|
||||
|
||||
## Key Architectural Improvements
|
||||
|
||||
1. **Clear Separation of Concerns**
|
||||
- Hammer throwing vs. hammer behavior
|
||||
- Player controller vs. player state vs. hammer equipment
|
||||
- Enemy AI vs. enemy spawning
|
||||
|
||||
2. **Centralized Game State**
|
||||
- GameManager handles all global state
|
||||
- LevelManager orchestrates progression
|
||||
- No scattered state management
|
||||
|
||||
3. **Event-Driven Architecture**
|
||||
- Systems communicate via events
|
||||
- Loose coupling between systems
|
||||
- Easy to add new features
|
||||
|
||||
4. **Extensible Gameplay Systems**
|
||||
- Noise system can be expanded for more sounds
|
||||
- Enemy states make new behaviors easy to add
|
||||
- Hammer can be enhanced with additional effects
|
||||
|
||||
5. **Inspector-Friendly**
|
||||
- Tunable parameters for game feel
|
||||
- Debug modes for testing
|
||||
- Clear assignment fields
|
||||
|
||||
---
|
||||
|
||||
## Files Summary
|
||||
|
||||
**New Files (3):**
|
||||
- `Managers/GameManager.cs`
|
||||
- `Managers/LevelManager.cs`
|
||||
- `Managers/NoiseSystem.cs`
|
||||
|
||||
**Modified Files (9):**
|
||||
- `Managers/UIManager.cs` (renamed from UiManager)
|
||||
- `Player/HammerThrower.cs` (refactored)
|
||||
- `Combat/Hammer.cs` (refactored)
|
||||
- `Enemies/EnemyAI.cs` (refactored)
|
||||
- `Environment/BreakableWall.cs` (updated)
|
||||
- `Environment/Chest.cs` (updated)
|
||||
- `Environment/KeyChest.cs` (updated)
|
||||
- `Environment/Door.cs` (refactored)
|
||||
- `Environment/DoorInteract.cs` (refactored)
|
||||
|
||||
**Renamed:**
|
||||
- `CharacterSpawner.cs` → `EnemySpawner.cs`
|
||||
|
||||
**Moved (folder reorganization only, no content changes):**
|
||||
- Multiple scripts distributed into logical folders
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
- All existing gameplay is preserved
|
||||
- The changes follow Unity best practices
|
||||
- Systems are designed to be maintainable and extensible
|
||||
- Debug modes can be disabled before release
|
||||
- No major breaking changes - mostly additive improvements
|
||||
|
||||
**Status:** ✅ **All tasks complete and ready for testing**
|
||||
Reference in New Issue
Block a user