精华内容
下载资源
问答
  • protobuf unity

    2016-05-05 21:07:18
    各语言的protobuf库,包括编译文件,unity 可用
  • Protobuf Unity

    2014-12-30 19:48:41
    Protobuf 使用方法 http://blog.csdn.net/wuming0108/article/details/42270637
  • protobuf for unityunity中使用protobuf工程示例,数据的序列化和反序列化工程示例
  • protobuf-unity

    2018-10-19 16:44:39
    https://github.com/5argon/protobuf-unity Automatic .proto files compilation in Unity project to C# as you edit them...protobuf-unity Sirawat Pitaksarit / 5argon - Exceed7 Experiments Do you want ...

    https://github.com/5argon/protobuf-unity

    Automatic .proto files compilation in Unity project to C# as you edit them.

    protobuf-unity

    Sirawat Pitaksarit / 5argon - Exceed7 Experiments

    settings

    Do you want to integrate protobuf as a data class, game saves, message to the server, etc. in your game? Now you can put those .proto files directly in the project, work on it, and have this generate the classes for you.

    Functions

    1. When you write a .proto file normally you need to use the protoc command line to generate C# classes. This plugin automatically find all your .proto files in your Unity project, generate them all, and output respective class file at the same place as the .proto file. It automatically regenerate when you change any .proto file.

    If there is an error the plugin will report via the Console.

    1. Now, your generated class will contains using Google.Protobuf. Which means you must have Google.Protobuf.dll in your Unity project.

    Updates

    • (1/12/2017) Now include paths is not only the folder of the file that is being compiled, but all folders that has a .protofile in your project. Proto includes on the .proto file's header does not support ... etc. so this way you can use an unqualified name to reference any .proto file in your Unity project. Split assembly is available in 2017.3 and it uses folder hierarchy. This can help you split up your proto files.
    • (29/07/2018) There is a package.json so you could use Unity Package Manager now. Google for how to do it locally and according to Unity Berlin talk we will be able to use UPM with GitHub address directly later. I am preparing for that.

    Problem with iOS + IL2CPP

    Now that you can't use mono backend anymore on iOS, there is a problem that IL2CPP is not supporting System.Reflection.Emit. Basically you should avoid anything that will trigger reflection as much as possible.

    Luckily the most of core funtions does not use reflection. The most likely you will trigger reflection is protobufClassInstance.ToString() (Or attempting to Debug.Log any of the protobuf instance.) It will then use reflection to scan figure out what is the structure of all the data just to print out pretty JSON-formatted string. To alleviate this you might override ToString so that it pull the data out to make a string directly from generated class file's field. I am not sure of other functions that might trigger reflection.

    You should see the discussion in this and this thread. The gist of it is Unity failed to preserve some information needed for the reflection and it cause the reflection to fail at runtime.

    And lastly the latest protobuf (3.6.0) has something related to this issue. Please see https://github.com/google/protobuf/blob/master/CHANGES.txt So it is recommended to get the latest version!

    Installation

    1. Put files in your Unity project
    2. You can access the settings in Preferences > Protobuf. Here you need to put a path to your protoc executable.

    settings

    1. As soon as you import/reimport/modify (but not moving) .proto file in your project, it will compile only that file to the same location as the file. If you want to temporary stop this there is a checkbox in the settings, then you can manually push the button in there if you like. Note that deleting .proto file will not remove its generated class.

    Prerequisites

    Requires protoc. This plugin does not include protoc command and will try to run it from your command line (via .NET System.Diagnostics.Process.Start). Please see https://github.com/google/protobuf and install it. Confirm with protoc --version in your command prompt/terminal.

    Some notes about Protocol Buffer

    For complete understanding I suggest you visit Google's document but here are some gotchas you might want to know before starting.

    • Use CamelCase (with an initial capital) for message names – for example, SongServerRequest. Use underscore_separated_names for field names – for example, song_name.
    • By default of C# protoc, the underscore_names will become PascalCase and camelCase in the generated code.
    • .proto file name matters and Google suggests you use underscore_names.proto. It will become the output file name in PascalCase. (Does not related to the file's content or the message definition inside at all.)
    • Field index 1 to 15 has the lowest storage overhead so put fields that likely to occur often in this range.
    • The generated C# class will has sealed partial.
    • You cannot use enum as map's key.
    • It's not int but int32. And this data type is not efficient for negative number. (In that case use sint32)

    project

    code compare

    Problems

    Works on macOS. Untested on Windows/Linux since I am not developing games in those environments. If you encountered any problems please use the Issue section or send a PR if you manages to fix it. Thank you.

    License

    As this includes protobuf you need to follow Google's license here : https://github.com/google/protobuf/blob/master/LICENSE

    For my own Unity code the license is MIT without requiring any attributions. (The part where it says "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software." is not required.) You are welcome to include it if you want.

    展开全文
  • Protobuf_Unity.zip

    2020-05-24 14:58:06
    Protobuf_Unity.zipProtobuf_Unity.zipProtobuf_Unity.zipProtobuf_Unity.zipProtobuf_Unity.zipProtobuf_Unity.zipProtobuf_Unity.zip
  • Protobuf For Unity

    2018-06-06 15:09:31
    适合刚开始学习Protubuf的同学,里面有说明文档的链接
  • 开发环境: 系统:win7系统64位内存16G ...这篇博客主要实现在Unity中使用Protobuf,包括Protobuf下载、Protobuf文件编译、Unity导入ProtobufUnity中使用Protobuf 一、Protobuf下载 1、通过github下载 ...

    开发环境:
    系统:win7系统64位内存16G
    软件:Unity2019
    参考资料/博客:https://zhuanlan.zhihu.com/p/75510885

    主要内容

    这篇博客主要实现在Unity中使用Protobuf,包括Protobuf下载、Protobuf文件编译、Unity导入Protobuf、Unity中使用Protobuf

    一、Protobuf下载
    1、通过github下载
    https://github.com/protocolbuffers/protobuf/releases
    编译工具:
    在这里插入图片描述
    用于UnityProtubuf源码:
    在这里插入图片描述
    2、csdn下载
    编译工具:https://download.csdn.net/download/yyl80/12504824
    Protobuf C#源码:https://download.csdn.net/download/yyl80/12504817
    二、protobuf文件编译

    1、利用记事本建立test.txt文件,输入:

    syntax = "proto3";
    package Mytest;
    import "google/protobuf/timestamp.proto";
    option csharp_namespace = "Mytest.Detatil";
    message Test_Person
    {
    string name =1;
    int32 level =2;
    string profession = 3;
    
    enum area
    {
    ch = 0;
    us = 1;
    uk = 2;
    }
    message Person_all
    {
    	string num =1;
    	area type =2;
    }
    repeated Person_all all =4;
    google.protobuf.Timestamp last_time =5;
    }
    

    2、将test.txt文件另存为test.proto文件
    3、将test.proto文件移动到下载的编译工具bin文件夹中,将下载的编译工具中include文件夹也移动到bin文件夹,按下shift键并右键鼠标,选择在此处打开命令窗口,输入:

    protoc.exe --csharp_out=. test.proto
    

    最终会生成一个C#文件

    在这里插入图片描述
    三、Unity导入Protobuf源码
    将下载的Protobuf源码解压,移动到Unity工程中的Assets文件夹里面,等待Unity编译完成即可。

    四、Unity中使用Protobuf

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Mytest.Detatil;
    using System.IO;
    using Google.Protobuf;
    public class testProtoBuf : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            Test_Person _Person = new Test_Person
            {
                Name = "老王",
                Level =12,
                Profession = "法师",
    
                All = { new Test_Person.Types.Person_all { Num = "123", Type = 0 } }
    
            };
    
            using (var output = File.Create("Test.txt"))
            { //写入stream
                _Person.WriteTo(output);
            }
            //转json
            var json = _Person.ToString();
            //转bytestring
            var byteStr = _Person.ToByteString();
            //转byte数组
            var byteArr = _Person.ToByteArray();
    
    
            //解析
            using(var input = File.OpenRead("Test.txt"))
            {
                //stream 解析
                _Person = Test_Person.Parser.ParseFrom(input);
                //字节串解析
                _Person = Test_Person.Parser.ParseFrom(byteStr);
                //字节数组解析
                _Person = Test_Person.Parser.ParseFrom(byteArr);
                //json解析
                _Person = Test_Person.Parser.ParseJson(json);
            }
    
    
    
            }
    
        // Update is called once per frame
        void Update()
        {
    
            
        }
    }
    
    展开全文
  • ProtobufUnity中的应用

    千次阅读 2017-01-08 19:55:00
    Protobuf是一种数据交换格式,由于它是一种二进制的格式,比使用xml 进行数据交换快许多 ...开发工具:VS、Unity Protobuf官网:点击打开链接 资源提供: 【VS项目】 使用VS新建一个C#空项目 右键点

    Protobuf是一种数据交换格式,由于它是一种二进制的格式,比使用xml 进行数据交换快许多

    可以把它用于分布式应用之间的数据通信或者异构环境下的数据交换

    作为一种效率和兼容性都很优秀的二进制数据传输格式,可以用于诸如网络传输、配置文件、数据存储等诸多领域

    开发工具:VS、Unity

    Protobuf官网:点击打开链接

    资源提供:点击打开链接

    【VS项目】

    使用VS新建一个C#空项目

    右键点击引用

    选择NuGet程序包->搜索Protobuf(这里我选择protobuf-net.Enyim)

    点击下载安装后创建一

    Person.cs对象来实战一个序列化和反序列话的应用程序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using ProtoBuf;
    
    namespace ProtobufObj
    {
        [ProtoContract]
        class Person
        {
            [ProtoMember(1)]
            public int id
            {
                get;
                set;
            }
            [ProtoMember(2)]
            public string name
            {
                get;
                set;
            }
            [ProtoMember(3)]
            public string address
            {
                get;
                set;
            }
        }
    }
    

    接下来实现序列化与反序列化的函数

    封装了两中函数接口,分别是转化为字符串与文件

    新建ProtobufHelper.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using ProtoBuf;
    using System.IO;
    
    namespace ProtobufObj
    {
        class ProtobufHelper
        {
            //将对象序列化为字符串
            public static string SerializerToString<T>(T t)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    Serializer.Serialize(ms,t);
                    return ASCIIEncoding.UTF8.GetString(ms.ToArray());
                }  
            }
    
            //将对象序列化到文件
           public static void SerializerToFile<T>(T t,string filePath)
            {
                using (var file = File.Create(filePath))
                {
                    Serializer.Serialize(file,t);
               }
            }
    
    
           //将字符串转化为对象
           public static T DederializerFromString<T>(string str)
           {
               //using作为语句,用于定义一个范围,在此范围的末尾将释放对象
               //将字符串转化为内存流
               using (MemoryStream ms=new MemoryStream(ASCIIEncoding.UTF8.GetBytes(str)))
               {
                   T obj = Serializer.Deserialize<T>(ms);
                   return obj;
               }     
           }
    
            //将文件数据转化为对象
            public static T DederializerFromFile<T>(string filePath)
           {
               using (var file = File.OpenRead(filePath))
               {
                   T obj = Serializer.Deserialize<T>(file);
                   return obj;
               }
           }
        }
    }
    

    最后测试下

    新建Program.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using ProtoBuf;
    
    
    namespace ProtobufObj
    {
        class Program
        {
            public static void Main(string[] args)
            {
                
                Person person = new Person
                {
                    id=1,
                    name="即步",
                    address="江西赣州"
                };
    
                //序列化
                string str=ProtobufHelper.SerializerToString<Person>(person);
    
                //反序列化
                Person obj=ProtobufHelper.DederializerFromString<Person>(str);
            }
        }
    }
    

    调试程序,发现一起正常,Person对象被序列化为二进制字符串

    当然也可以转化到文件

    【Unity】

    在VS项目后,我们在项目的Debug文件目录下可以找到protobuf-net.dll

    在unity中新建一个名为Plugins文件,将protobuf-net.dll拷贝到其中

    将Person.cs、Program.cs、ProtobufHelper.cs拷贝到unity中

    修改Program.cs文件目录为:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ProtoBuf;
    using UnityEngine;
    
    
    namespace ProtobufObj
    {
        class Program : MonoBehaviour
        {
            void Start()
            {
                
                Person person = new Person
                {
                    id=1,
                    name="即步",
                    address="江西赣州"
                };
    
                //序列化
                string str=ProtobufHelper.SerializerToString<Person>(person);
                Debug.Log(str);
          
    
                //反序列化
                Person obj=ProtobufHelper.DederializerFromString<Person>(str);
            }
        }
    }
    

    运行程序,一些正常



    展开全文
  • protobufunity中使用

    2020-08-09 15:36:01
    1、下载protobuf的release版本 protobuf3.12.4 Release 2、解压,用vs打开,并生成解决方案,Release/debug均可 3、将生成的几个文件放到Assets中的Plugins文件夹中,没有该文件夹就新创建一个 4、写自己的.proto...

    1、下载protobuf的release版本
    protobuf3.12.4 Release
    2、解压,用vs打开,并生成解决方案,Release/debug均可
    在这里插入图片描述
    在这里插入图片描述
    3、将生成的几个文件放到Assets中的Plugins文件夹中,没有该文件夹就新创建一个
    在这里插入图片描述
    4、写自己的.proto消息定义文件,写法proto3 syntax
    5、将自己的.proto文件编译成.cs文件,需要下载protoc,就在1的下载页面中,解压后命令编译即可
    在这里插入图片描述
    在这里插入图片描述
    6、将编译好的文件拷贝到自己的项目中即可使用,如下例子
    在这里插入图片描述

    另外

    这些编译生成的类的统一父类是IMessage,结构上有要求的可以直接使用这个父类作为参数

    展开全文
  • ProtobufUnity使用DLL方式调用(IOS可用), 在真机上亲测
  • protobufunity中的应用

    2018-02-08 09:56:01
    首先,将protobuf——net的dll文件放到Assets的Plugins里面创建一个protobufhelper的脚本,这个脚本负责序列化和反序列化using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
  • unity使用protobuf-net见这里 https://blog.csdn.net/qq_35107322/article/details/110396018 服务器快速安装 1 yum install protobuf-devel 2 项目的make文件加入 -lprotobuf 3 编写proto文件 4 根据proto文件生成c...
  • 代码很简单直接上了 ...using ProtoBuf;using UnityEngine;using System.IO;using System; public class Test2 : MonoBehaviour{ private void Start() { NetModel item = new NetModel() { ...
  • .NET的Socket+KCP+ProtobufUnity局域网联机测试范例, 大量功能待补充。
  • Unity3d-ProtoBufunity3d +编辑器窗口中进行Protobuf查询,以从protobuf文件生成C#源代码 如何使用 将proto-buf文件夹放在资产文件夹的根目录下 打开ProtoBuf编辑器窗口工具-> ProtoBuf 在“编辑器”窗口中...
  • ProtoBufUnity3D中的简单使用!

    千次阅读 2016-08-15 10:42:26
    目前Unity3D依然是移动手机开发的主流开发工具。 而在移动端推荐的打包解包方法是使用Protobuf协议:主要优点就是效率高,传输量小,节省带宽。而想要在Android和IOS端都能使用Protobuf,我使用的方法是把Protobuf-...
  • 将xls转成protobufUnity使用的流程

    千次阅读 2015-04-14 20:00:07
    将xls转成protobufUnity使用的流程 通用流程图 流程图 通用流程图简述 在python运行时下,依赖proto组件、xlrd的组件,使用xls_deploy_tool.py处理Hello.xls,生成Hello.data数据文件、及其...
  • 看完这篇文章你基本就能够在客户端使用protobuf 3.2 使用UDP协议发送byte流 使用的protobuf模型: syntax = "proto3"; // proto协议版本 message Player{ int32 id = 1;//同上 int32 hp = 2;//必须字段,在...
  • unity-protobuf3

    2019-02-27 19:13:04
    unity通讯之protobuf文件传输,protobuf3序列化与反序列化。
  • Unity Protobuf简单测试

    2020-03-12 10:53:41
    Protobuf ...在Unity中使用Protobuf 两种方式: 1.导入Unity专用的Protobuf-net资源包,用C#代码定义对象。 2.配置.net的Protobuf环境,用原生的.proto文件定义对象。 我使用第一种方法使用unity版...
  • Unity3D 游戏引擎 protobuf_for_unity Google 的 protobuf 3.0.x,unity3D 游戏引擎。 protocolbuffer 是google 的一种数据交换的格式,它独立于语言,独立于平台。google 提供了多种语言的实现:java、c#、c++、go...
  • unity使用protobuf

    2020-07-17 16:39:07
    unity中使用protobuf和服务器进行通信 proto文件 syntax = "proto2"; enum Cmd { INVALID_CMD = 0; eLoginReq = 1; eLoginRes = 2; } message LoginReq { required string name = 1; required int32 age ...
  • Unity使用protobuf

    2018-05-17 16:41:29
    Google的Protobuf 本身是没有.net版本的。.net版的protobuf来源于proto社区,有两个版本:一个版本叫protobuf-net,下载地址为:http://code.google.com/p/protobuf-net/ 写法上比较符合c#一贯的写法,而且效率更高...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 651
精华内容 260
关键字:

protobufunity