cocos 获取所有节点组件信息

cocos 获取所有节点组件信息

在浏览器控台输入一下代码运行即可

var scene = cc.director.getScene();
var nodeList = new Array();
var total = 0;
var startTime = new Date().valueOf();
var searchNode = function (node) {
    nodeList.push(node);
    total++;
    for (var i = 0; i < node.childrenCount; i++) {
        searchNode(node.children[i]);
    }
};
var startSearchNode = function () {
    total = 0;
    startTime = new Date().valueOf();
    nodeList = new Array();
    searchNode(scene);
    console.log("searchNode total:" + total + " time:" + (new Date().valueOf() - startTime));
};
var nodeComponentMsglist = [];
var getComponentList = function () {
    nodeComponentMsglist = [];
    nodeList.forEach(function (node) {
        var obj = { nodeName: node.name, componentCount: node._components.length, componentNameListText: null };
        var componentNameList = node._components.map(function (component) {
            return component.name;
        });
        obj.componentNameListText = componentNameList.join(' ');
        nodeComponentMsglist.push(obj);
    });
};
var outputNodeList = function () {
    startSearchNode();
    getComponentList();
    console.table(nodeComponentMsglist);
};
outputNodeList();

 

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容