前言
饥荒里面装备栏有三个地方,手,身体,头。上一期我们讲了戴头上的帽子,这期我们讲讲穿在身上的衣服。事实上,衣服的代码比帽子的简单点,不过需要的贴图会多点。
总览与下载
源文件已添加到mods/~myclothes.zip中
饥荒联机版开发
https://pan.baidu.com/s/1_-TPRdo86z8PNwK084N_3A?pwd=oc74
modmain
modmain,modinfo这些和往常的一样即可,没什么需要特别注意的地方。
GLOBAL.setmetatable(env,{
__index=function(t,k) return GLOBAL.rawget(GLOBAL,k) end})
PrefabFiles = {
"myclothes"
}
STRINGS.NAMES.MYCLOTHES = "我的衣服"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.MYCLOTHES = "虽然是木甲的图"
prefab
核心代码如下,其中 equippable 组件是可装备物品的核心,在设置的装备/卸载回调函数中替换玩家的贴图。其他组件自由组装即可。其中注释掉那些是可选的
local assets =
{
Asset("ANIM", "anim/myclothes.zip"), --动画
Asset("IMAGE", "images/inventoryimages/myclothes.tex"), --物品栏贴图
Asset("ATLAS", "images/inventoryimages/myclothes.xml"),
}
local function onequip(inst, owner)
owner.AnimState:OverrideSymbol("swap_body", "myclothes", "swap_body")
end
local function onunequip(inst, owner)
owner.AnimState:ClearOverrideSymbol("swap_body")
end
local function fn()
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddNetwork()
--物品栏类型的物理碰撞
MakeInventoryPhysics(inst)
--动画
inst.AnimState:SetBank("myclothes")
inst.AnimState:SetBuild("myclothes")
inst.AnimState:PlayAnimation("anim")
--可漂浮
MakeInventoryFloatable(inst)
inst.entity:SetPristine()
if not TheWorld.ismastersim then
return inst
end
--可检查
inst:AddComponent("inspectable")
--物品栏显示
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.imagename = "myclothes"
inst.components.inventoryitem.atlasname = "images/inventoryimages/myclothes.xml"
--[[燃料
inst:AddComponent("fuel")
inst.components.fuel.fuelvalue = TUNING.LARGE_FUEL
--]]
--[[自然,火传递
MakeSmallBurnable(inst, TUNING.SMALL_BURNTIME)
MakeSmallPropagator(inst)
--]]
--[[护甲
inst:AddComponent("armor")
inst.components.armor:InitCondition(TUNING.ARMORWOOD, TUNING.ARMORWOOD_ABSORPTION) --:InitCondition(amount, absorb_percent)
--]]
--可装备
inst:AddComponent("equippable")
inst.components.equippable.equipslot = EQUIPSLOTS.BODY
--[[
inst.components.equippable.dapperness = TUNING.DAPPERNESS_SMALL --装备回san值
inst.components.equippable.walkspeedmult = 2 --装备后移速倍率
--]]
inst.components.equippable:SetOnEquip(onequip)
inst.components.equippable:SetOnUnequip(onunequip)
--可作祟
--MakeHauntableLaunch(inst)
return inst
end
return Prefab("myclothes", fn, assets)
动画
衣服的动画其实也很简单,因为用的是替换贴图,所以我们只需要准备对应的图片,以及一个扔地上的动画即可。
先来看下木甲的图是什么样的,其中左边是木甲的图,右边是温蒂身体部分的图。
前三张对应正面,之后三张是侧面,再之后三张是后面的。
剩下两张分别是编号11和编号13的,编号11的不知道哪里用到,编号13的是作为地面上的图片使用的,他们的编号都在10以上,也就是替换贴图的时候不影响具体的显示。
再来看看scml,老样子先设置下锚点,编号1-10的锚点位置的设置会影响穿在身上的效果,可以多调几次,然后进游戏看看效果。
最后一张编号13的作为地面上的贴图,动画就一个,把图片拖进来,然后改下右下角的名字即可(对应代码里的)