local goodsItem = GUI:ItemShow_Create(iconBg, "goodsItem" .. Index, GUI:getContentSize(iconBg).width / 2, GUI:getContentSize(iconBg).height / 2, { itemData = itemCfg, index = Index, look = true })
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-06-12 11:56:05 |
👁️ 阅读: 15
这行代码是使用996引擎的`GUI:ItemShow_Create`函数创建一个物品展示控件。
**代码解析:**
```lua
local goodsItem = GUI:ItemShow_Create(
iconBg, -- 父节点
"goodsItem" .. Index, -- 唯一ID(动态生成)
GUI:getContentSize(iconBg).width / 2, -- X坐标(父节点中心)
GUI:getContentSize(iconBg).height / 2, -- Y坐标(父节点中心)
{ -- 物品配置数据
itemData = itemCfg, -- 物品数据
index = Index, -- 物品索引
look = true -- 可查看(允许点击查看详情)
}
)
```
**参数说明:**
1. **iconBg** - 父节点控件对象
2. **"goodsItem" .. Index** - 控件唯一标识,使用字符串拼接确保唯一性
3. **GUI:getContentSize(iconBg).width / 2** - 计算父节点宽度的一半作为X坐标
4. **GUI:getContentSize(iconBg).height / 2** - 计算父节点高度的一半作为Y坐标
5. **配置表** - 包含物品显示所需的数据
**常见配置项:**
- `index` - 物品ID(必需)
- `itemData` - 物品详细数据
- `look` - 是否允许查看(true/false)
- `count` - 显示数量
- `bgVisible` - 是否显示背景框
- `color` - 品质颜色
这种写法通常用于在UI中动态创建物品图标,比如背包、商店、拍卖行等界面。
← 返回问答库