Skip to content

windpersuer/protobuf_net_for_unity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protobuf_net_for_unity

google's protobuf 2.* for Unity3d 2018

source: google's protobuf
version: 2.*
apply to: Unity3d 2018
notes: Unity 5.0 and before version, please use protobuf_for_unity version

instruction:
open the unity project: unity_project_protobuf_net


notice the 'NewBehaviourScript.cs' click unity run

    private void _TestProtobuff ()
    {
        //1. new a message.
        TheMsg message_1 = new TheMsg ();
        message_1.Name = "steve jobs";
        message_1.Num = 19550224;
        Debug.Log ("message1: " + message_1.ToString());

        //2. write byte buffer to file.
        byte[] byte_buffer;
        using (MemoryStream memoryStream = new MemoryStream())
        {
            message_1.WriteTo (memoryStream);
            byte_buffer = memoryStream.ToArray ();
        }

        //3. read message from byte buffer.
        TheMsg message_2 = TheMsg.Parser.ParseFrom (byte_buffer);
        Debug.Log ("message2: " + message_2.ToString ());
    }

log out:


it worked!

at last, cd './ProtoGen/', click 'protogen.bat' to generate './input/test_msg.cs' into './output/test_msg.cs'
and copy 'test_msg.cs' to unity project

and 'test_msg.proto' in ./ProtoGen/input/

protobuf
syntax = "proto2";

message TheMsg {
  string name = 1;
  int32 num = 2;
}

About

google's protobuf-net 2.0 for unity2017

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages