源始链接: http://rimworldwiki.com/wiki/Modding_Tutorials/Items
在本教程中,我们将创建一种新的物品,它可以被拖运和消耗.
先决条件:
您应该已经阅读入门章节,它让您快速的了解RimWorld的模组结构.您同时已经熟悉各文件的位置(如About.xml,def XML文件,在哪里放材质贴图等等).
创建目录:
如果您尚未按入门章节创建了ThingDef目录,您还需要创建一个新的文件夹保存您的xml文件,在Defs文件夹内创建
文件夹,至此目录创建完成.ThingDefs
创建新的资源(钛金属为例)
(描述删节,框架代码)
<?xml version="1.0" encoding="utf-8" ?>
<Resources>
</Resources>
创建资源的属性基类,在<Resources> 和 </Resources>之间添加如下代码
<ThingDef Name="ResourceBase" Abstract="True">
<defName>base_Resource</defName>
<thingClass>ThingResource</thingClass>
<label>Unspecified resource</label>
<category>Item</category>
<eType>Item</eType>
<resourceCountPriority>Middle</resourceCountPriority>
<useStandardHealth>true</useStandardHealth>
<selectable>true</selectable>
<maxHealth>100</maxHealth>
<altitudeLayer>Item</altitudeLayer>
<stackLimit>75</stackLimit>
<purchasable>true</purchasable>
<comps>
<li><compClass>CompForbiddable</compClass></li>
</comps>
<beauty>Ugly</beauty>
<alwaysHaulable>true</alwaysHaulable>
<drawGUIOverlay>true</drawGUIOverlay>
<rotatable>false</rotatable>
<pathCost>15</pathCost>
</ThingDef>
不做任何修改,我们可以重载新资源def的所有东西,同样在</Resources>前添加如下代码:
<ThingDef ParentName="ResourceBase">
<defName>Titanium</defName>
<label>Titanium</label>
<description>A rare strong and useful metal.</description>
<texturePath>Things/Item/Resource/Titanium</texturePath>
<interactSound>MetalDrop</interactSound>
<basePrice>3</basePrice>
<useStandardHealth>false</useStandardHealth>
<storeCategories>
<li>ResourcesRaw</li>
</storeCategories>
</ThingDef>
但愿您阅读Thingdef章节时能理解每个属性的含义.
测试:
略
结论:
略