#protobufjs 本插件基于protobufjs 6.8.0版本,主要针对自己的项目进行了一点点更改,使之能正常的在跨平台上面使用
#适用范围: cocos creator 1.6版本(1.6之前的版本没有测试过), 如果有问题可以直接联系我QQ657542753
#用法: 导入项目,并设置为插件(ps:不要问我怎么导入为插件,不然我打死你!官方文档是有相关介绍的)
#更改 #game对象是一个自定义的全局变量,如果大家喜欢用全局变量,可以在以下目录的文件中添加以下内容 window.game = {}
需要添加的文件: creator安装目录下: /Resources/static/simulator/main.js //该目录是用于模拟器的 /Resources/static/preview-templates/boot.js //web /Resources/static/build-templates/shares/main.js //打包模板
function pool(alloc, slice, size) {
var SIZE = size //|| 8192;
var MAX = SIZE >>> 1;
var slab = null;
var offset = SIZE;
return function pool_alloc(size) {
if (size < 1 || size > MAX)
return alloc(size);
if (offset + size > SIZE) {
slab = alloc(SIZE);
offset = 0;
}
var buf = slice.call(slab, offset, offset += size);
if (offset & 7) // align to 32 bit
offset = (offset | 7) + 1;
return buf;
};
}
function fetch(filename, options, callback) {
if (typeof options === "function") {
callback = options;
options = {};
} else if (!options)
options = {};
if (!callback)
return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
// if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
console.log("cc.sys.isNative)",cc.sys.isNative)
if (cc.sys.isNative)
try {
// 这边通过解析文件名字,然后用cc.loader.load来加载文件
var start_idx = filename.lastIndexOf("/") + 1
var end_idx = filename.lastIndexOf(".")
var name = filename.substring(start_idx, end_idx)
var data = game.ResMgr.getProto(name)
return callback(null, data.content)
} catch (e) {
return null;
}
// use the XHR version otherwise.
return fetch.xhr(filename, options, callback);
}
// name = applyCase(name)