UnityProtobuf的使用与常见问题
Posted 霍莉雪特
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UnityProtobuf的使用与常见问题相关的知识,希望对你有一定的参考价值。
Protobuf的使用流程
protobuf参考教程:https://www.jianshu.com/p/b135676dbe8d
手写.proto文件后,用CMD命令行运行protoc.exe编译器,进入.proto文件路径生成C#文件,再把C#文件放到Unity项目中使用。
插件protobuf-net:http://www.cnblogs.com/xuf22/articles/3504399.html
原因是官方Protobuf的C#实现要求.Net4.6及以上,而Unity使用的.Net过低版本(老版本最高.Net3.5,具体要看是用的Unity的版本)。
在已写好的C#实体类中加上打标签。
插件protobuf-unity:https://github.com/5argon/protobuf-unity
这是Unity编辑器插件。Protobuf正常使用流程是手写.proto文件后,用CMD命令行运行protoc.exe编译器,进入.proto文件路径生成C#文件,再把C#文件放到Unity项目中使用。该插件可自动寻找Unity项目中所有.proto文件并一键生成所有对应的C#文件(出现在与每个.proto文件相同的目录下)。并且当.proto文件被修改时会自动重新生成C#文件!
插件protobuf_for_unity
https://github.com/GongFaxin/protobuf_for_unity 或 https://github.com/bitcraftCoLtd/protobuf3-for-unity
常见问题
Missing input file
命令行使用protoc.exe时,报错Missing input file。即当前设置的--proto_path目录下找不到.proto文件。如下图,protoc.exe与person.proto文件在同一目录下的。
Unity不支持.Net3.5及以上





以上是关于UnityProtobuf的使用与常见问题的主要内容,如果未能解决你的问题,请参考以下文章
UIPinchGestureRecognizer 与 UILongTapGestureRecognizer 的使用没有问题