Cocos Creator 3D 对 protobufjs的支持问题

之前在Cocos Creator 2.x 的版本里都能正常使用protobufjs。

现在使用3D做新项目,protobufjs不能使用了,各种报错,论坛也有说是Creator 3D使用的是ES6的标准,但是protobufjs还是使用的老的标准。

请问,有人将 protobufjs 改写为 ES6 版本的经验吗?或者有没有其他的解决方案?

还分es6?

文章还没发,用的是最新版的pb啊

@echo off
setlocal enabledelayedexpansion

echo 开始生成客户端消息体js
start “生成proto客户端js” /i /wait /min cmd /c “pbjs --no-create --no-verify --no-convert -t static-module -w closure -o ./TankContest.js ./TankContest.proto”
echo 将客户端消息体js处理用做插件(压缩+合并protobuf)
start “压缩+合并js到插件” /i /wait /min cmd /c “uglifyjs ./protobuf-minimal.min.js ./TankContest.js -o …\TankContest.Client-Creator3D\TankContest\assets\0_Plugin_MessageProtobuf.min.js”

echo 开始生成服务端消息体js
start “生成proto服务端js” /i /wait /min cmd /c “pbjs --no-create --no-verify --no-convert -t static-module -w default -o …\TankContest.NodeServer\tankContestServer\Net\TankContest.js ./TankContest.proto”

start “生成通用定义文件d.ts” /i /wait /min cmd /c “pbts -o ./TankContest.d.ts ./TankContest.js”

echo 单独处理客户端的d.ts
set file=TankContest.d.ts
set replaced=export
set all=declare
for /f “skip=1 delims=” %%i in (‘type “%file%”’) do (
set str=%%i
set “str=!str:%replaced%=%all%!”
echo !str!>>"%file%"_tmp
)
move “%file%”_tmp “…\TankContest.Client-Creator3D\TankContest\ExternalDefine\TankContest.d.ts”

echo 拷贝d.ts到服务端
copy “TankContest.d.ts” “…\TankContest.NodeServer\tankContestServer\Net\TankContest.d.ts” /y

echo 清理临时文件
del /q TankContest.js
del /q TankContest.d.ts

echo 完成
pause

蛮贴一下我生成proto的批处理吧(静态方式使用,并且只用了encode+decode的方式)
信息都在命令中哈

用到的npm库,自行全局安装
额外的protobuf-minimal.min.js文件,自行官方下载,放在同一目录
assets\0_Plugin_MessageProtobuf.min.js
在Creator3D面板中将这个脚本设置为插件,三个都打勾