Difference between revisions of "Modding Tutorials/Custom Comp Classes"

From RimWorld Wiki
Jump to navigation Jump to search
(Creation, xml)
 
m (Fixed formatting :p)
Line 10: Line 10:
 
=== Basic outline ===
 
=== Basic outline ===
 
You will have some custom def and it will have something like this:
 
You will have some custom def and it will have something like this:
<source lang="xml">
+
  <ThingDef ...>
<ThingDef ...>
+
    ...
  ...
+
    ...
  ...
+
    <comps>
  <comps>
+
      <<nowiki>li</nowiki> Class="MyNamespace.MyCompProperties">
    <li Class="MyNamespace.MyCompProperties">
+
        <myCustomCompProperty>some value</myCustomCompProperty>
      <myCustomCompProperty>some value</myCustomCompProperty>
+
        <mySecondCompProp>4</mySecondCompProp>
      <mySecondCompProp>4</mySecondCompProp>
+
      </<nowiki>li</nowiki>>
    </li>
+
      <<nowiki>li</nowiki>>
    <li>
+
        ''<<nowiki>!--</nowiki> this is kind of like <tag>MN.MyCustomTag</tag>:-->''
      <!-- this is kind of like <tag>MN.MyCustomTag</tag>-->
+
        <compClass>MyNamespace.MyCustomThingComp</compClass>
      <compClass>MyNamespace.MyCustomThingComp</compClass>
+
      </<nowiki>li</nowiki>>
    </li>
+
    </comps>
  </comps>
+
  </ThingDef>
</ThingDef>
 
</source>
 
  
  
 
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]
 
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]

Revision as of 16:17, 29 November 2018

Creating a custom comp class is a convenient way to add new functionality to RimWorld.

Prerequisites

def (xml) and C# structure

Basic outline

You will have some custom def and it will have something like this:

 <ThingDef ...>
   ...
   ...
   <comps>
     <li Class="MyNamespace.MyCompProperties">
       <myCustomCompProperty>some value</myCustomCompProperty>
       <mySecondCompProp>4</mySecondCompProp>
     </li>
     <li>
       <!-- this is kind of like <tag>MN.MyCustomTag</tag>:-->
       <compClass>MyNamespace.MyCustomThingComp</compClass>
     </li>
   </comps>
 </ThingDef>