@nsqks/prototools

1.0.2 • Public • Published

protoTool

介绍

批量自动化处理在cocos creator TS 中使用.proto文件的流程

软件架构

在文件夹中创建好自己的.proto文件,并配置好自己的路径,可参考test.js

生成文件完成后,将我们安装的全局protobuf模块中的dist/protobuf.js拖到cocos creator 编辑器中,设置为插件并勾选所有的插件设置

如何使用生成的这些文件

使用方式:

   // account.proto
   package protoTest;
   //角色对象
   message Player
   {
       optional int64 id = 1;
       optional string name = 2;
       optional int32 level = 3;//等级
   }

   // 会生成两个文件  account.js account.d.ts
   // 放入到cocos creator 脚本中
   // 在代码中引入
   // 使用

   import protoTest from "./account" // 相对路径
   let ob = {
           id: 1,
           name:"nsqks",
           level:9
       }
   let accountProtobuf = protoTest.Player.create(ob);
   let buf = protoTest.Player.encode(accountProtobuf).finish();
   cc.log(buf);
   let testData = protoTest.Player.decode(buf);
   cc.log(testData);
   // 如果还有疑问可参考:https://blog.csdn.net/nsqks/article/details/113878372 本工具是该博文中国提到的处理流程的自动化工具

Readme

Keywords

none

Package Sidebar

Install

npm i @nsqks/prototools

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

16.1 kB

Total Files

8

Last publish

Collaborators

  • nsqks