Modding Tutorials/Writing custom code
Jump to navigation
Jump to search
This page was originally created by TheTynan.
This tutorial gives you a broad idea how to work on a C# solution.
Requirements
- This tutorial requires you to have set up a solution.
Writing custom code
- Create a new class in a new code file:
- In your IDE project file browser, right-click (YourProjectName), Add -> New item -> C# or .NET -> Class;
- Rename the class to what you want the class name to be, e.g DamageWorker_FlameExtension,
- You’ll want to add these namespace to the top of each of your .cs source files as necessary;
using UnityEngine; //For all Unity functionality, rendering, resource management using AI; //RimWorld AI using Sound; //RimWorld sound subsystem using UI; //RimWorld GUI
- Write your class;
- Decompile source code to take a look at the game's existing code;
- If you still get stuck on anything, any modding questions can be asked on the subforum,
- Compile your class into a .dll;
- Make sure your project's output type is "class library";
- Note: by default, Visual Studio will compile all the references of the project as well, so you’ll get a copy of UnityEngine.dll and Assembly-CSharp.dll and some others. You don’t need these. Just take YourModName.dll,
- Place the .dll in the YourModName/Assemblies folder of your mod;
- Reference the classes in your .dll from the xml data in the YourModName/Defs folder;
- Example: Create a new ThingDef with a <thingClass> that points to a class in your .dll,
- The game should load your class now;
See also
- Distribution details how to release your mod.
- Assembly modding example contains a small modding example.