Unity3D protobuf-net使用方式
1、下载protobuf-net
2、创建Unity工程,创建一个Plugins文件夹,将protobuf-net解压把里面得protobuf-net放到Plugins

3、创建一个名为mcs的文本文件,里面写上-unsafe

4、重启Unity
5、编译自动生成cs代码工具

protogen.exe就是刚才生成的

6、编写.proto文件

message.proto里写入
message TeamCharacterOne
{
required uint64 CharacterId = 1;
required string CharacterName = 2;
required int32 RoleId = 3;
required int32 Level = 4;
required int32 Ladder = 5;
required int32 FightPoint = 6;
optional int32 QueueResult = 7;
}
7、 生成.cs代码
创建一个proto.bat文件文件
里面写入
@echo off
rem 查找文件
for /f "delims=" %%i in ('dir /b ".\*.proto"') do echo %%i
rem 转cpp for /f "delims=" %%i in ('dir /b/a "*.proto"') do protoc -I=. --cpp_out=. %%i
for /f "delims=" %%i in ('dir /b/a "*.proto"') do protogen -i:%%i -o:%%~ni.cs
pause
8、把代码放入Unity工程
9、写测试代码
using message;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine; public class NewBehaviourScript : MonoBehaviour { // Use this for initialization
void Start () {
var a = new TeamCharacterOne();
a.CharacterId = 10;
a.CharacterName = "fdsafd";
var b = Serialize(a); var data = Deserialize<TeamCharacterOne>(b);
Debug.Log(data.CharacterName);
} // Update is called once per frame
void Update () { } byte[] Serialize(object o)
{
using (MemoryStream ms = new MemoryStream())
{
ProtoBuf.Serializer.Serialize(ms, o);
byte[] result = new byte[ms.Length];
ms.Position = 0;
ms.Read(result, 0, result.Length); return result;
}
} T Deserialize<T>(byte[] b)
{
using (MemoryStream ms = new MemoryStream())
{ ms.Write(b, 0, b.Length);
ms.Position = 0;
return ProtoBuf.Serializer.Deserialize<T>(ms);
}
}
}
Unity3D protobuf-net使用方式的更多相关文章
- 在ios android设备上使用 Protobuf (使用dll方式)
http://game.ceeger.com/forum/read.php?tid=13479 如果你的工程可以以.Net 2.0 subset模式运行,请看这个帖子中的方法. 地址:http://g ...
- (转)在ios android设备上使用 Protobuf (使用dll方式)
自:http://game.ceeger.com/forum/read.php?tid=13479 如果你的工程可以以.Net 2.0 subset模式运行,请看这个帖子中的方法. 地址:http:/ ...
- 编写Unity3D着色器的三种方式
不管你会不会写Unity3D的shader,估计你会知道,Unity3D编写shader有三种方式,这篇东西主要就是说一下这三种东西有什么区别,和大概是怎样用的. 先来列一下这三种方式: fixed ...
- 投影方式- Unity3D游戏开发培训
投影方式- Unity3D游戏开发培训 作者:Jesai 2018-02-12 20:33:13 摘 要 透视投影是3D渲染的基本概念,也是3D程序设计的基础.掌握透视投影的原理对于深入理解其他 ...
- 【Unity3D基础】让物体动起来①--UGUI鼠标点击移动
背景 首先还是先声明自己是比较笨的一个人,总是找不到高效的学习方法,目前自己学习Unity3D的方式主要是两种,一种是直接看高质量的源码,另一种是光看不行还要自己动手,自己写一些有代表性的小程序,这也 ...
- google protobuf ios开发使用
简介: protobuf 即 google protocol buffer 是一种数据封装格式协议: 比如其他经常用的xml,json等格式:protobuf的优势是效率高,同样的一份数据使用prot ...
- Protocol Buffers(Protobuf)开发者指南---概览
Protocol Buffers(Protobuf)开发者指南---概览 欢迎来到protocol buffers的开发者指南文档,protocol buffers是一个与编程语言无关‘.系统平台无关 ...
- protobuf 向前兼容向后兼容
http://blog.163.com/jiang_tao_2010/blog/static/12112689020114305013458/ 不错的protobuf.. protobuf的编码方式: ...
- Linux下protobuf的编译与安装【各种奇葩问题】
1.下载源码 首先,从github上下载protobuf的源码,地址:https://github.com/google/protobuf,我选择下载2.5.0版本. 2.编译protobuf 2.1 ...
- Linux下protobuf的编译与安装
1.下载源码 首先,从github上下载protobuf的源码,地址:https://github.com/google/protobuf,我选择下载2.5.0版本. 2.编译protobuf 将下载 ...
随机推荐
- 输出到网页前台js代码中包含单引号的处理方法
描述:后台输出js到前台,如 <script type="text/javascript"> //<![CDATA[ var aStepD ...
- GCT之数学公式(微积分)
- Backlight当前行背景高亮显示
下载地址:https://github.com/limejelly/Backlight-for-XCode PS:Xcode 8.0 默认支持了 跟VVDocumenter规范注释生成器的安装方式一样 ...
- 如何用BarTender将日期变量和序列号变量放一起打印成条码?
刚接触BarTender 2016的小伙伴们可能对条码的数据源还不太搞的定,例如有时需要将日期变量和序列号变量放一起打印成条码,那如何简单达到目的呢?下面,小编教大家解决这一问题的三大步骤. 1.在B ...
- mySql的desc与explain分析性能(主要分析索引)
desc select * from A where id =‘110’; 查询结果的含义请参考:http://www.2cto.com/database/201209/156466.html
- phoenix连接hbase数据库,创建二级索引报错:Error: org.apache.phoenix.exception.PhoenixIOException: Failed after attempts=36, exceptions: Tue Mar 06 10:32:02 CST 2018, null, java.net.SocketTimeoutException: callTimeou
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
- webpack流程图
- JS匿名函数理解
匿名函数的基本形式为(function(){...})(); 前面的括号包含函数体,后面的括号就是给匿名函数传递参数并立即执行之 匿名函数的作用是避免全局变量的污染以及函数名的冲突 1.小括号的作 ...
- c#直接调用ssis包实现Sql Server的数据导入功能
调用ssis包实现Sql Server的数据导入功能网上已经有很多人讨论过,自己参考后也动手实现了一下,上一次笔者的项目中还用了一下这个功能.思前想后,决定还是贴一下增强记忆,高手请54. 1.直接调 ...
- PMP模拟考试-2
1. Increasing resources on the critical path activities may not always shorten the length of the pro ...