Unity3d v5.3+protoBuf

一、先去 https://github.com/mgravell/protobuf-net/tree/master/protobuf-net 把protobuf-net的代码下载下来。node

二、使用Monodevelop打开protobuf-net-master/protobuf-net/protobuf-net.csproj,而后右键选择Build protobuf-net 项目。在protobuf-net-master/protobuf-net/目录下会生成一个bin的目录。(选择Release)git

三、把protobuf-net.dll复制到protobuf-net-master/ProtoGen/目录下,而后使用MonoDevelop打开protobuf-net-master/ProtoGen/ProtoGen.csproj 工程,添加引用(以下图),build ProtoGengithub

四、这时会在ProtoGen/bin/生成protogen.exe,而后把整个protobuf-net-master文件夹复制到win操做系统,没有win的能够安装一个虚拟机。c#

五、执行protogen.exe -i:a.proto -o:a.cs,则会在本目录生成一个a.cs的c#文件ui

六、把protobuf-net-master/protobuf-net/源代码拷贝到unity工程scritps目录下(能够把bin文件夹去掉),a.cs文件添加到scripts文件中,这是会有一个unsafe的错误。spa

七、在Assets目录下添加smcs.rsp文件,文件内容只有-unsafe。重启unity,错误消失。操作系统

八、解析数据。(下面是本地proto数据解析)。code

FileStream fs = null;
        try{
            fs = new FileStream (Application.dataPath+"/StreamingAssets/64.proto",FileMode.Open,FileAccess.Read);
        }catch(Exception ex){
            Debug.LogError (ex.Message);
        }
        CMaindata mainData = new CMaindata();
        mainData = ProtoBuf.Serializer.Deserialize<CMaindata> (fs);

九、大功告成!!!ip

相关文章
相关标签/搜索