Jump to content

Recommended Posts

local assets =
{
    Asset("ANIM", "anim/unit.zip"),  --地上的动画
    Asset("ATLAS", "images/inventoryimages/unit_cal.xml"), --加载物品栏贴图
    Asset("IMAGE", "images/inventoryimages/unit_cal.tex"),
    Asset("IMAGE", "images/inventoryimages/unit_com.xml"),
    Asset("IMAGE", "images/inventoryimages/unit_com.tex"),
    Asset("IMAGE", "images/inventoryimages/unit_war.xml"),
    Asset("IMAGE", "images/inventoryimages/unit_war.tex"),
}

local function commonfn(anim, tag)
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("unit")  --地上动画
    inst.AnimState:SetBuild("unit")
    inst.AnimState:PlayAnimation(anim)

    if tag ~= nil then
        inst:AddTag("units")
    end

    MakeInventoryFloatable(inst, "med", nil, 0.6)

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    -- 可检查组件
    inst:AddComponent("inspectable")
    inst:AddComponent("stackable")
    inst:AddComponent("inventoryitem") -- 添加物品组件
    inst.components.inventoryitem.atlasname = "images/inventoryimages/unit_" .. anim .. ".xml" -- 确保物品贴图路径正确
    MakeHauntableLaunch(inst)

    return inst
end
local function unit_purple()
    return commonfn("cal", nil)
end

local function unit_blue()
    return commonfn("com", nil)
end

local function unit_red()
    return commonfn("war", nil)
end

return Prefab("unit_calculate", unit_purple, assets),
    Prefab("unit_comparison", unit_blue, assets),
    Prefab("unit_weapon", unit_red, assets)

Ask for advice, either in English or Chinese is okay.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...