Development Environment
Prerequisites
- Visual Studio 2019 or newer
- Visual Studio Code (optional)
- Unity 2019.4.28f1 or newer
- Cities: Skylines with the latest version
Setting Up Your Development Environment
Installing Visual Studio
- Download and install Visual Studio.
- Launch Visual Studio and select the Game Development with Unity workload during installation.
- Install any additional components required for Unity development.
Installing Visual Studio Code (Optional)
- Download and install Visual Studio Code.
- Install the C# for Visual Studio Code extension from the Visual Studio Code Marketplace.
Installing Unity
- Download and install Unity.
Creating a new Visual Studio Project
- After installing Visual Studio, launch the application.
- Click on Create a new project with the "Class Library" template for C# projects.
See screenshot
- Choose a name and location for your project and click Create.
- Add references to the Unity assemblies located in the
Managed
folder of your Cities: Skylines installation directory.- For Steam users, the default path is
C:\Program Files (x86)\Steam\steamapps\common\Cities_Skylines\Cities_Data\Managed
. - For Epic Games users, the default path is
C:\Program Files\Epic Games\CitiesSkylines\Cities_Data\Managed
. - For non-Steam users, the default path is
C:\Program Files (x86)\Cities Skylines\Cities_Data\Managed
. - For Mac users, the default path is
~/Library/Application Support/Steam/steamapps/common/Cities_Skylines/Cities.app/Contents/Managed
.
- For Steam users, the default path is
- Start coding your mod using the Unity API and C# scripting.
- Build your project and copy the resulting DLL file to the
Mods
folder of your Cities: Skylines installation directory. You can build the project by clicking on Build > Build Solution in Visual Studio or by usingctrl + shift + b
keyboard shortcut.
Debugging Your Mod
Using Visual Studio
- Open your project in Visual Studio.
- Set breakpoints in your code by clicking on the left margin of the code editor.
- Click on Debug > Start Debugging or press
F5
to start debugging your mod. - Attach the debugger to the Cities: Skylines process by selecting the appropriate process from the list.
Using Visual Studio Code
- Open your project in Visual Studio Code.
- Set breakpoints in your code by clicking on the left margin of the code editor.
- Click on Run > Start Debugging or press
F5
to start debugging your mod. - Attach the debugger to the Cities: Skylines process by selecting the appropriate process from the list.
See Performance Metrics
Using Visual Studio
- Open your project in Visual Studio.
- Click on Debug > Performance Profiler to open the Performance Profiler.
- Select the desired profiling target (e.g., CPU Usage, Memory Usage, etc.).
- Click on Start to start profiling your mod.
- Analyze the performance metrics to identify bottlenecks and optimize your mod.
Automatically Copying the Mod DLL to the Mods
Folder (Optional)
To automatically copy the mod DLL to the Mods
folder of Cities: Skylines after building the project, you can add a post-build event in Visual Studio.
Using Visual Studio
- Open your project in Visual Studio.
- Right-click on your project in the Solution Explorer and select Properties.
- Click on Build Events in the left pane.
- Enter the following command in the Post-build event command line box to create and copy the mod DLL to the
Mods
folder of Cities: Skylines:
mkdir "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)"
del "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)\$(TargetFileName)"
xcopy /y "$(TargetPath)" "%LOCALAPPDATA%\Colossal Order\Cities_Skylines\Addons\Mods\$(SolutionName)"