PlayerSuperEquip = {}----角色面板 时装
PlayerSuperEquip._ui = nil
function PlayerSuperEquip.main(data)
PlayerSuperEquip.posSetting = {
17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 43, 45
}
local parent = GUI:Attach_Parent()
loca
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-04-17 15:29:05 |
👁️ 阅读: 6
你的点击事件代码有问题,主要是 `ui` 的获取方式不正确。
问题出在这一行:
```lua
local ui = PlayerSuperEquip.parent._ui
```
正确的写法应该是:
```lua
local ui = PlayerSuperEquip._ui
```
因为 `PlayerSuperEquip._ui` 已经在前面通过 `GUI:ui_delegate(parent)` 获取到了。修改后的完整代码应该是:
```lua
function PlayerSuperEquip.main(data)
PlayerSuperEquip.posSetting = {
17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 43, 45
}
local parent = GUI:Attach_Parent()
local path = "player/player_super_equip_node_win32"
GUI:LoadExport(parent, path)
PlayerSuperEquip._ui = GUI:ui_delegate(parent)
if not PlayerSuperEquip._ui then
return false
end
PlayerSuperEquip._parent = parent
PlayerSuperEquip._hideNodePos = {}
local fashionSwitch = SL:GetMetaValue("GAME_DATA", "Fashionfx")
PlayerSuperEquip._show_naked_mold = fashionSwitch and tonumber(fashionSwitch) or 0 --是否显示裸模 0开启 1关闭
PlayerSuperEquip.playerSex = SL:GetMetaValue("SEX") --角色性别
PlayerSuperEquip.playerHairID = SL:GetMetaValue("HAIR") --发型
PlayerSuperEquip.playerJob = SL:GetMetaValue("JOB") --职业
-- 这里修改为正确的ui引用
local ui = PlayerSuperEquip._ui
GUI:addOnClickEvent(ui["Button_1"], function()
SL:Print("界面=====================================================")
end)
--初始化装备槽
PlayerSuperEquip.InitEquipCells()
--初始化是否显示时装开关
PlayerSuperEquip.InitEquipSetting()
return true
end
```
另外,浮生梦老师提醒你:在获取角色性别、发型、职业的元数据时,按照前端课程内容,应该使用完整的键名:
- `SL:GetMetaValue("L.M.SEX")` 而不是 `SL:GetMetaValue("SEX")`
- `SL:GetMetaValue("L.M.HAIR")` 而不是 `SL:GetMetaValue("HAIR")`
- `SL:GetMetaValue("L.M.JOB")` 而不是 `SL:GetMetaValue("JOB")`
这样修改后,你的点击事件就能正常工作了。下次写代码时要仔细检查变量名哦,不懂的可以随时问浮生梦老师!
← 返回问答库