Mac下 cocos creator 中使用protobuf,JS/TS项目完整流程
因项目需求,入坑cocos creator,面临的第一个问题就是protobuf的使用,在网上看了很多教程,讲的都已经很完善,但我还是用了两三天才搞出来,这里总结一下经验。
友情提示:JS项目只需看步骤1~4;TS项目需要看全部步骤;
1、准备工作
1)、proto文件
文件名Message.proto:
syntax = “proto3”;
package ProtobufTest;
//客户端检测链接请求
message Request {
string userId = 1;
string userName = 2;
string userToken = 3;
}
2)、安装protobufjs
npm install protobufjs -g
安装成功后可以看到你的protobufjs版本和安装路径,cd到protobufjs目录下
然后使用open . (打开当前目录)
找到目录下dist/protobuf.js文件,直接拖到cocos crea