A Unity-based simulation featuring autonomous agents in a procedurally generated world. The project implements a custom Entity Component System (ECS) architecture to manage complex agent behaviors and world interactions.
The project uses a custom ECS implementation with three main pillars:
- WorldManager: Core orchestrator that manages systems and entities
- Entities: Game objects that contain components
- Components: Data containers that define entity properties
- Systems: Logic processors that operate on entities with specific components
- Centralized message bus for system communication
- Type-safe message publishing and subscription
- Priority-based message processing (Low, Normal, High, Critical)
- Automatic message queue management
- Built-in message types:
- SystemInitializedMessage: Sent when systems initialize
- TimeChangedMessage: Sent on day/night cycle changes
- ResourceStateChangedMessage: Sent when resources update
- NPCNeedsChangedMessage: Sent when NPC needs change
- TerrainChunkGeneratedMessage: Sent when terrain generates
- Procedural terrain generation using multiple noise layers
- Seamless chunk-based world loading
- Multiple biomes (Plains, Forest, Mountains, Desert)
- Smooth transitions between chunks and biomes
- Dynamic LOD and chunk management based on viewer position
NPCs are autonomous agents with:
- Needs: Hunger, Thirst, Energy, Social
- Personality Traits:
- Sociability: Influences desire for social interaction
- Bravery: Affects risk-taking behavior
- Curiosity: Drives exploration
- Diligence: Impacts work ethic and task focus
- States:
- Movement: Idle, Moving
- Activities: Working, Resting, Eating, Drinking
- Social: Interacting, Socializing
- Behaviors:
- Dynamic decision-making based on needs and personality
- Pathfinding and terrain-aware movement
- Resource seeking and consumption
- Social interaction with other NPCs
- NPC Generation:
- Configurable initial population
- Random name assignment
- Customizable spawn radius and positioning
- Group spawning capabilities
- Initialization:
- Randomized movement properties (speed, rotation, interaction range)
- Unique personality trait generation
- Initial needs randomization
- Optional visual representation through prefabs
- Resource Types:
- Food: Consumable for hunger needs
- Water: Consumable for thirst needs
- RestArea: Used for energy recovery
- WorkArea: Designated work locations
- Resource Properties:
- Quantity tracking
- Consumption rates
- Quality multipliers
- Automatic replenishment
- Infinite/finite resources
- Resource Management:
- Usage tracking
- Depletion mechanics
- Replenishment delays
- Visual feedback through Gizmos
- Configurable day/night cycle:
- Customizable day length
- Dawn, Day, Dusk, Night periods
- Transition periods (dawn/dusk)
- Time Management:
- Real-time to game-time conversion
- Day counting and period tracking
- Progress tracking within each day
- Environmental Impact:
- Influences NPC behavior patterns
- Affects resource availability
- Modifies terrain visualization
- Uses FastNoiseLite for coherent noise generation
- Multiple noise layers for varied terrain:
- Base terrain layer
- Biome variation layer
- Detail noise layer
- Smooth chunk transitions using edge blending
- Custom terrain shader for biome visualization
- Needs-based decision making
- Personality-influenced behavior
- Dynamic target selection
- Social interaction system
- Resource seeking and consumption
- Terrain-aware movement
- Chunk-based world loading
- Entity pooling
- Efficient component lookup
- Dependency-aware system initialization
Assets/
├── Scripts/
│ └── ECS/
│ ├── Core/
│ │ ├── WorldManager.cs # Central ECS orchestrator
│ │ ├── Entity.cs # Base entity class
│ │ ├── ComponentBase.cs # Base component class
│ │ ├── SystemBase.cs # Base system class
│ │ └── Messaging/ # Message-based communication
│ │ ├── Message.cs # Base message class
│ │ ├── MessageBus.cs # Message routing and handling
│ │ └── SystemMessages.cs # Built-in message types
│ ├── Components/
│ │ ├── NPCComponent.cs # NPC properties and state
│ │ ├── ResourceComponent.cs # Resource properties
│ │ ├── TerrainDataComponent.cs # Terrain chunk data
│ │ ├── TimeComponent.cs # Time management
│ │ └── VoxelData.cs # Voxel-based data structures
│ └── Systems/
│ ├── NPCSystem.cs # NPC behavior management
│ ├── ResourceSystem.cs # Resource management
│ ├── TerrainSystem.cs # Terrain generation and management
│ ├── TimeSystem.cs # Time simulation
│ └── SpawnerSystem.cs # Entity spawning
- Unity Universal Render Pipeline (URP)
- Custom TerrainShader for biome visualization
- FastNoiseLite for procedural generation
- Automatic component registration
- System dependency resolution
- Event-based component updates
- Efficient entity querying
- Message-based system communication:
- Decoupled system interactions
- Priority-based message processing
- Automatic subscription management
- Type-safe message handling
- Multi-threaded chunk generation
- Seamless chunk stitching
- Biome blending
- Height-based biome distribution
- State machine-based behavior system
- Need-based decision making
- Dynamic target selection
- Social interaction mechanics
- Resource consumption logic
- Sophisticated resource type system with multiple categories
- Dynamic usage tracking and state management
- Configurable regeneration mechanics:
- Customizable replenishment rates
- Delayed regeneration options
- Quality-based consumption effects
- Proximity-based discovery and interaction
- Visual debugging through Unity Gizmos