Difference between revisions of "Modding Tutorials/Writing custom code"
Jump to navigation
Jump to search
(Added category) |
(Made the numbered list easier to read; any comments on the current step are now sub-steps.) |
||
Line 1: | Line 1: | ||
In addition to creating data for the game to use, you can also write code. You could probably write in any .NET language, but I’ve only tested C#. | In addition to creating data for the game to use, you can also write code. You could probably write in any .NET language, but I’ve only tested C#. | ||
− | # Create a new class library project in your code editor of choice. | + | # Create a new class library project in your code editor of choice; |
+ | ## Viable code editors include [https://www.visualstudio.com/ Visual Studio], [http://www.monodevelop.com/download/ MonoDevelop] and [http://www.icsharpcode.net/OpenSource/SD/Download/ SharpDevelop], | ||
# In your project, add references to these DLLs:<br/><pre>(RimWorldInstallFolder)/RimWorld_Data/Managed/Assembly-CSharp.dll (RimWorldInstallFolder)/RimWorld_Data/Managed/UnityEngine.dll</pre> | # In your project, add references to these DLLs:<br/><pre>(RimWorldInstallFolder)/RimWorld_Data/Managed/Assembly-CSharp.dll (RimWorldInstallFolder)/RimWorld_Data/Managed/UnityEngine.dll</pre> | ||
− | # In your project properties, change the target framework to .NET 3.5 | + | # In your project properties, change the target framework to .NET 3.5; |
− | # Create a new class in a new code file | + | # Create a new class in a new code file; |
− | # You’ll want to add these namespace to each of your source files as necessary | + | # You’ll want to add these namespace to each of your source files as necessary;<br/><pre>using UnityEngine; //For all Unity functionality, rendering, resource management using AI; //RimWorld AI using Sound; //RimWorld sound subsystem using UI; //RimWorld GUI </pre> |
− | # Write your class | + | # Write your class; |
− | # Compile your class into a .dll | + | ## [[Modding Tutorials/Decompiling source code|Decompile source code]] to take a look at the game's existing code; |
− | # Place the .dll in the | + | ## If you still get stuck on anything, any modding questions can be asked on the [https://ludeon.com/forums/index.php?board=14.0 subforum], |
− | # Reference the classes in your .dll from the xml data in the YourModName/Defs folder | + | # Compile your class into a .dll; |
− | # The game should load your class now | + | ## 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; | ||
+ | # '''Optional:''' Release your source code. | ||
+ | ## Most mods include a YourModName/Source folder with the full C# project in it for other modders to check out; | ||
+ | ## Some mods include a Dropbox download link to their source code in the mod's topic. This is also a possibility.<br/><br/> | ||
+ | ==See also== | ||
− | You can find a small tutorial project here: [[Modding Tutorials/Assembly Modding Example]] | + | * You can find a small tutorial project here: [[Modding Tutorials/Assembly Modding Example]] |
[[Category:Modding tutorials]] | [[Category:Modding tutorials]] |
Revision as of 14:46, 11 July 2015
In addition to creating data for the game to use, you can also write code. You could probably write in any .NET language, but I’ve only tested C#.
- Create a new class library project in your code editor of choice;
- Viable code editors include Visual Studio, MonoDevelop and SharpDevelop,
- In your project, add references to these DLLs:
(RimWorldInstallFolder)/RimWorld_Data/Managed/Assembly-CSharp.dll (RimWorldInstallFolder)/RimWorld_Data/Managed/UnityEngine.dll
- In your project properties, change the target framework to .NET 3.5;
- Create a new class in a new code file;
- You’ll want to add these namespace to each of your 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;
- Optional: Release your source code.
- Most mods include a YourModName/Source folder with the full C# project in it for other modders to check out;
- Some mods include a Dropbox download link to their source code in the mod's topic. This is also a possibility.
See also
- You can find a small tutorial project here: Modding Tutorials/Assembly Modding Example