前言
pbkiller在cc1.10后失效了,当我尝试观赏源码时,发现了奎神绕了一个小弯路。
略看了新版protobuf的api,结合cc.Asset的新特性。可以轻易的解决pb问题。
API
Protobuf
protobuf.parse
/**
- Parses the given .proto source and returns an object with the parsed contents.
- @param {string} source Source contents .proto的源代码
- @param {Root} root Root to populate root对象,可为空。不为空时可连续收纳数个proto类
- @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted. 不太了解。如果有大神讲解,麻烦在下面回帖
- @returns {IParserResult} Parser result 看下面的类定义
- @property {string} filename=null Currently processing file name for error reporting, if known
-
@property {IParseOptions} defaults Default {@link IParseOptions}
*/
function parse(source, root, options)
IParseResult
/**
- Result object returned from {@link parse}.
- @interface IParserResult
- @property {string|undefined} package Package name, if declared
- @property {string[]|undefined} imports Imports, if any
- @property {string[]|undefined} weakImports Weak imports, if any
-
@property {string|undefined} syntax Syntax, if specified (either
"proto2"or"proto3") -
@property {Root} root Populated root instance
*/
Cocos Creator
1.10以后,.proto等文本文件加载后为TextAsset类。可通过text属性访问文本信息。
cc.loader.loadRes(path,callback)