Editing Modding Tutorials/Writing custom code
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
{{BackToTutorials}} | {{BackToTutorials}} | ||
− | |||
− | This tutorial | + | ''This tutorial requires you to have [[Modding Tutorials/Setting up a solution|set up a solution]].''<br/><br/> |
− | + | 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#.<br/><br/> | |
− | + | # 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;<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; | |
− | + | ## [[Modding Tutorials/Decompiling source code|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 [https://ludeon.com/forums/index.php?board=14.0 subforum], | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | # [[Modding Tutorials/Decompiling source code|Decompile source code]] to take a look at the game's existing code; | ||
− | ## If you get stuck on anything, any modding questions can be asked on the [https://ludeon.com/forums/index.php?board=14.0 subforum], | ||
# Compile your class into a .dll; | # Compile your class into a .dll; | ||
− | |||
## Make sure your project's output type is "class library"; | ## 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. Just take '' | + | ## '' '''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'', |
− | # Reference the classes in your .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, | |
− | ## '''Example:''' Create a new ThingDef with a <thingClass> that points to a class in your .dll | ||
# The game should load your class now;<br/><br/> | # The game should load your class now;<br/><br/> | ||
− | = | + | ==See also== |
− | |||
− | |||
− | |||
− | + | * You can find a small tutorial project here: [[Modding Tutorials/Assembly Modding Example]] | |
− | * [[ | ||
[[Category:Modding tutorials]] | [[Category:Modding tutorials]] |