CozyCityBuilderPrototype: A Unity Isometric City Builder
April 2, 2025
Project Overview
Today I want to share details about my Unity-based isometric city building game prototype. CozyCityBuilderPrototype is designed with relaxation in mind, allowing players to create their own cozy little cities at their own pace.
I've always been fascinated by city builders and management games. There's something deeply satisfying about watching a city grow from nothing into a bustling metropolis. With this project, I wanted to focus on creating a calm, stress-free building experience rather than the more frantic resource management seen in some city builders.
Core Features
- Isometric Tile-based Map System: The game uses a classic isometric perspective with a tile-based foundation
- Building System: Players can place and delete various buildings on the map
- Camera Controls: Intuitive camera movement for navigating around the map
- Save/Load System: Cities persist between sessions with JSON-based saving
- Interaction Systems: Clean, intuitive UI for building placement
Technical Implementation
The project leverages Unity's built-in systems while adding custom functionality where needed. Here's a breakdown of the key technical aspects:
Code Structure
The codebase follows a modular approach, organized into several logical directories:
-
Building System: Contains interfaces and implementations for all building-related functionality
// Building interface example interface IBuilding { void Place(Vector3 position); void Remove(); BuildingType GetBuildingType(); }
-
Controller System: Manages player interaction and camera movement
// Example of interaction mode switching public enum InteractionMode { CameraControl, ObjectPlacement, ObjectDeletion }
-
Tile Map System: The foundation of the game world
// Tilemap generation example public class TilemapGenerator : MonoBehaviour { // Handles creation and management of the isometric grid private TileData[,] mapData; public void GenerateMap(int width, int height) { mapData = new TileData[width, height]; // Initialize tiles... } }
Design Patterns Used
The project implements several design patterns to ensure clean, maintainable code:
- Strategy Pattern: Used for different interaction modes (camera control, object placement)
- Observer Pattern: For UI updates when game state changes
- Factory Pattern: Used for creating different building types
- Singleton Pattern: For manager classes that need global access
Challenges and Solutions
One of the most challenging aspects was implementing the isometric coordinate system. Converting between world, grid, and screen coordinates required careful math:
// Converting screen position to isometric grid position public Vector2Int ScreenToGridPosition(Vector3 screenPosition) { Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPosition); // Convert world position to isometric grid position int x = Mathf.FloorToInt(worldPos.x / tileSize + worldPos.y / (tileSize/2)); int y = Mathf.FloorToInt(worldPos.y / (tileSize/2) - worldPos.x / tileSize); return new Vector2Int(x, y); }
Another challenge was optimizing the rendering for large maps. I implemented a chunking system that only renders tiles visible to the camera, significantly improving performance on larger maps.
Player Controls
The control scheme is designed to be intuitive and user-friendly:
- C key: Switch to camera control mode
- P key: Switch to placement mode
- D key: Switch to deletion mode
- Mouse drag: Move camera or place/delete objects depending on the current mode
Save System
The save system uses JSON serialization to store all relevant game data:
// Save data structure [Serializable] public class SaveData { public int mapWidth; public int mapHeight; public Listtiles = new List (); [Serializable] public class SerializedTile { public int x; public int y; public int type; public int buildingId; } }
Future Development
While this is currently a prototype, I have several features planned for future development:
- Resource management system
- Citizen AI and population simulation
- Day/night cycle with dynamic lighting
- Weather effects
- More building types and decorative options
Conclusion
This prototype serves as a solid foundation for building a complete city builder game. The focus on creating a relaxing experience has guided many design decisions, from the calming visual style to the intuitive controls.
If you're interested in game development, city building games, or Unity development, feel free to check out the project on GitHub. I welcome any feedback or contributions!
View Project on GitHub