RustLikeGame is an experimental Unity 6 prototype inspired by survival sandboxes such as Rust. The repository collects purpose-built modules for procedural voxel terrain generation, a modular building system with snap points, a FSM-driven construction flow, and an inventory UI wired through Zenject dependency injection.
- Project Overview
- Key Features
- Requirements
- Getting Started
- Project Structure
- Subsystems
- Additional Components
- Extensibility Tips
- License
The prototype targets desktop platforms and ships with preconfigured Zenject installers, a modular first-person controller, and UI scaffolding. It is meant to serve as a starting point for experimenting with survival mechanics, world streaming, and construction gameplay loops.
- Hybrid terrain generation: CPU, GPU, or hybrid voxel pipelines with LOD blending, frustum culling, and optional raycast-based culling.
- Modular construction flow: Ghost previews, snap points, stability propagation, and tier progression for placed structures.
- FSM-driven gameplay states: Dedicated construction state machine decoupled from player input.
- Resource-aware inventory: Stackable slots, hotbar selection, and resource cost validation shared across tools and building logic.
- Zenject-powered architecture: Installers configure all services for terrain, construction, UI, and player systems.
- Unity Editor: 6000.2.5f1.
- Unity packages: TextMesh Pro, Burst, Collections, Jobs (plus other default modules).
- Third-party: Zenject (via UPM).
- Target platform: PC (Standalone).
- Clone the repository and open the
RustLikeGamefolder with Unity 6000.2.5f1. - Load the
Assets/Scenes/MainScene.unityscene. - Ensure the following Zenject installers are present in the scene hierarchy:
TerrainSystemInstallerComputeBufferManagerInstallerConstructionInstallerPlayerInstaller
- Enter Play mode. Default controls:
- Movement: WASD + Mouse look
- Inventory:
E - Build Menu:
B - Placement distance: Mouse wheel
- Interactions: Left/Right mouse buttons with equipped tools
Assets/
├─ Installers/ # Zenject installers
├─ Scenes/ # Main scene(s)
├─ Scripts/
│ ├─ TerrainSystem/ # Voxel terrain generation & streaming
│ ├─ Building System/ # Construction logic and runtime objects
│ ├─ FSM 1.0/ # Finite state machine core and states
│ ├─ InventorySystem/ # Inventory logic and UI prefabs
│ └─ ModularFirstPersonController/ # FPS controller modules
└─ Resources, Materials, etc.
- TerrainManager orchestrates chunk generation and streaming, controls CPU/GPU/hybrid modes, manages generation budgets, LOD transitions, and culling (frustum with optional ray checks).
- TerrainSettingsAsset implements
ITerrainSettingsand stores chunk dimensions, render distance, LOD thresholds, and other tweakable parameters. - BiomeDefinition scriptable assets feed the
GenerateVoxelDataJobwith biome thresholds, noise parameters, height layers, caves, and domain warps. - Generation pipeline:
GenerateVoxelDataJob(Burst) produces density fields on the CPU.VoxelTerrainGPU.computehandles GPU density generation.MarchingCubesMeshGenerator(Burst) converts densities into meshes using gradients.ComputeBufferManager(IComputeBufferPool) reuses GPU buffers to avoid frequent allocations.
- Player integration:
PlayerInteractionsubmits terrain modification requests (dig/place) through the manager so neighbors are updated consistently.
- StateMachine component runs
Enter/Exit/Update/LateUpdatefor the active state and draws a debug GUI. - BaseState and StateWithChangeTracking provide convenient abstractions, with the latter guarding against multiple transitions per frame.
- BuildSM divides the construction lifecycle into:
NotInBuilding– idle while no buildable item is selected.Start– initializes placement and activates the ghost preview.Perform– updates preview meshes, handles collisions/snap points, awaits confirmation.Stop– finalizes placement or cancellation and cleans up.
- The FSM relies on
ConstructionSelectorandPlacerfor concrete actions.
- Data & factories:
ConstructionFactoryscriptable objects describe building types (IDs, prefabs, costs, appearance variants).Constructionbase class represents runtime structures; derived classes (Base,Wall,Door, etc.) implement placement logic.ConstructionInstallerregisters factories with Zenject.
- Placement flow:
ConstructionSelectorchooses the active factory via UI input.Placercontrols ghost previews, placement distance, snapping (UniversalConnector,SnapPointHolder,SnapPoint), collision checks, and resource validation throughInventoryManager.GhostModeControllertoggles materials and colliders for valid/invalid previews.
- Combat & stability:
ConstructionHealthtracks the currentBuildingTier, hit points, and neighboring elements, responding to damage (DamageInfo) and repair/upgrade costs (TierAppearance).- Foundations marked with
SetAsGroundedFoundationpropagate stability and trigger re-evaluation when destroyed.
- Tools & UI integration:
BuildingToolmanages hammer interactions: highlighting viaMaterialPropertyBlock, damage, repairs, upgrades, and info panels (TextMesh Pro + Image widgets).InputManagerandPlayerInputcentralize user input for combat, repairs, and hotbar selection.UIManageropens/closes inventory and building canvases while locking the FPS camera when UI is focused.
- InventoryManager controls an array of
InventorySlotinstances, handling add/remove operations, stacking, hotbar selection, and verifying/deductingResourceCostvalues used by construction and tools. - InventorySlot bridges logic with UI elements, supports drag-and-drop through
IDropHandler. - InventoryItem MonoBehaviour renders individual items, tracks stack counts, and updates labels.
- Item scriptable objects define type (block/tool/resource), tool parameters, sprites, damage definitions, and resource categories.
- Integration: Shared
InventoryManagerreferences are injected intoPlacer,BuildingTool, and other subsystems so resource checks stay consistent. - Hotbar shortcuts: Number keys
1–9swap the active slot; the mouse wheel moves placement previews without consuming items.
- ModularFirstPersonController supplies a configurable first-person movement stack registered through
PlayerInstaller. - UI Prefabs live under
Assets/Scripts/InventorySystem/Prefabs, providing HUD and inventory visuals. - Resources & Materials deliver base assets for voxel terrain and construction pieces.
- Adjust world generation by editing
TerrainSettingsAssetinstances instead of modifying code. - Add new building pieces by creating
ConstructionFactoryassets and derivedConstructionsubclasses. - Extend the construction FSM by inheriting from
BuildingStateorStateWithChangeTrackingfor new states. - Define new items through
Itemscriptable objects and reference them in inventories or cost lists.