matrix4x4 / protobuf_for_unity

google's protobuf 3 for unity3d game engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

protobuf_for_unity

google's protobuf 3.x for unity3D

来源: google's protobuf
版本号:3.x

使用方法:
将目录 Google.Protobuf 下的所有文件拷到 Unity 工程中。


接下来可以参考 test_msg.proto

syntax = "proto3";

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

以及 Test.cs

void Start ()
{
    TheMsg msg = new TheMsg();
    msg.Name = "am the name";
    msg.Num = 32;

    Debug.Log(string.Format("The Msg is ( Name:{0},Num:{1} )",msg.Name,msg.Num));

    byte[] bmsg;
    using (MemoryStream ms = new MemoryStream())
    {
        msg.WriteTo(ms);
        bmsg = ms.ToArray();
    }


    TheMsg msg2 = TheMsg.Parser.ParseFrom(bmsg);
    Debug.Log(string.Format("The Msg2 is ( Name:{0},Num:{1} )",msg2.Name,msg2.Num));

}

测试输出:


About

google's protobuf 3 for unity3d game engine


Languages

Language:C# 100.0%Language:Protocol Buffer 0.0%