Skip to content

Instantly share code, notes, and snippets.

@jareguo
Last active October 19, 2016 10:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jareguo/7f20001f099759be62dac7e6b76aec07 to your computer and use it in GitHub Desktop.
Save jareguo/7f20001f099759be62dac7e6b76aec07 to your computer and use it in GitHub Desktop.
运行时 Creator 调试工具集

在收藏夹中新增一个网页,将网址设为下面的其中一个源码。然后打开任一 Creator 页面,接着直接在收藏夹点击刚刚收藏的网址即可。

打印 Hierarchy

javascript:(function () {
    function visitNode (node, visitor) {
        visitor(node);
        var children = node._children;
        for (var i = 0; i < children.length; ++i) {
            visitNode(children[i], visitor);
        }
    }
    cc.Node.prototype.printPath = function () {
        var path = this.name;
        for (var parent = this.parent; parent instanceof cc.Node; parent = parent.parent) {
            path = parent.name + '/' + path;
        }
        var emoji;
        if (!this.active) {
            emoji = '\u2716\uFE0F';
        }
        else if (this.activeInHierarchy) {
            emoji = '\u2705';
        }
        else {
            emoji = '\u2611\uFE0F';
        }
        console.log(emoji + ' ' + path);
    };
    var roots = cc.director.getScene().children;
    for (var i = 0; i < roots.length; i++) {
        var root = roots[i];
        visitNode(root, function (node) {
            node.printPath();
        });
    }
})();

调试数组用的一个包装

function DebugArray () {
    this.buffer = [];
};
DebugArray.prototype.push = function (item) {
    this.buffer.push(item);
};
for (let i = 0; i < 1000; ++i) {
    cc.js.getset(DebugArray.prototype, '' + i,
        function () {
            return this.buffer[i];
        },
        function (value) {
            this.buffer[i] = value;
        }
    );
}
cc.js.getset(DebugArray.prototype, 'length',
    function () {
        return this.buffer.length;
    },
    function (value) {
        debugger;
        this.buffer.length = value;
    }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment