使用 生成控件代码工具 遍历cocos studio 控件 root 的所有节点

function UIBase:writeAllM_()
    local targetPlatform = cc.Application:getInstance():getTargetPlatform()
    -- 如果不是debug状态 并且不是win32 窗口
    if not G_ISDEBUG and targetPlatform ~= cc.PLATFORM_OS_WINDOWS then
        return
    end

    local writeAllM_
    writeAllM_ = function(node)
        local name = node:getName()
        if node and name and string.find(name, "m_") then 
            local writeStr = string.format("self.%s = g_seekWidgetByName(self._root,\"%s\")\n", name, name)
            print(writeStr)
            g_writeUIM_(writeStr)
            if string.find(name, "m_Button") then
                local wBtnStr = string.format("self:addTouchEventListenerWithType(self.%s,buttonTouchFunc,ccui.TouchEventType.ended)\n", name)
                print(wBtnStr)
                g_writeUIM_Button(wBtnStr)
            end
        end
        table.walk(node:getChildren(), function(child)
            writeAllM_(child)
        end)
    end
    writeAllM_(self._root)
end

生成代码

self.m_Panel_Up = g_seekWidgetByName(self._root,"m_Panel_Up")
self.m_Image_NmlAtk = g_seekWidgetByName(self._root,"m_Image_NmlAtk")
self.m_Image_AssSki_1 = g_seekWidgetByName(self._root,"m_Image_AssSki_1")
self.m_Image_AssSki_2 = g_seekWidgetByName(self._root,"m_Image_AssSki_2")
self.m_Image_AssSki_3 = g_seekWidgetByName(self._root,"m_Image_AssSki_3")
self.m_Image_AssSki_4 = g_seekWidgetByName(self._root,"m_Image_AssSki_4")
self.m_Image_AssSki_5 = g_seekWidgetByName(self._root,"m_Image_AssSki_5")
self.m_Image_AssSki_6 = g_seekWidgetByName(self._root,"m_Image_AssSki_6")
self.m_Button_RmvSki_1 = g_seekWidgetByName(self._root,"m_Button_RmvSki_1")
self.m_Button_RmvSki_2 = g_seekWidgetByName(self._root,"m_Button_RmvSki_2")
self.m_Button_RmvSki_3 = g_seekWidgetByName(self._root,"m_Button_RmvSki_3")
self.m_Button_RmvSki_4 = g_seekWidgetByName(self._root,"m_Button_RmvSki_4")
self.m_Button_RmvSki_5 = g_seekWidgetByName(self._root,"m_Button_RmvSki_5")
self.m_Button_RmvSki_6 = g_seekWidgetByName(self._root,"m_Button_RmvSki_6")
self.m_Image_SelSki = g_seekWidgetByName(self._root,"m_Image_SelSki")
self.m_Label_SkiName = g_seekWidgetByName(self._root,"m_Label_SkiName")
self.m_Label_SkiLv = g_seekWidgetByName(self._root,"m_Label_SkiLv")
self.m_Image_SkyType = g_seekWidgetByName(self._root,"m_Image_SkyType")
self.m_ProgressBar_Exp = g_seekWidgetByName(self._root,"m_ProgressBar_Exp")
self.m_Label_Exp = g_seekWidgetByName(self._root,"m_Label_Exp")

你可能感兴趣的:(使用 生成控件代码工具 遍历cocos studio 控件 root 的所有节点)